Skip to content

Commit

Permalink
Merge pull request #446 from tomoto/fix/recursion-error-in-initializa…
Browse files Browse the repository at this point in the history
…tion

fix: catch RecursionError in initialization
  • Loading branch information
gnikit authored Mar 1, 2025
2 parents 9a86506 + f00b8ea commit f7c3ecd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
9 changes: 8 additions & 1 deletion fortls/langserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,14 @@ def workspace_init(self):
pool.close()
pool.join()
for path, result in results.items():
result_obj = result.get()
try:
result_obj = result.get()
except Exception as e:
result_obj = (
"An exception has occured while initialising the workspace.\n"
f"Exception({(type(e))}): {e}\n"
+ f"Traceback: {traceback.format_exc()}"
)
if isinstance(result_obj, str):
self.post_message(
f"Initialization failed for file {path}: {result_obj}"
Expand Down
32 changes: 32 additions & 0 deletions test/test_server_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
import tempfile

import pytest
from setup_tests import Path, run_request, write_rpc_request

from fortls.constants import Severity


@pytest.fixture()
def setup_tmp_file():
levels = 2000
fd, filename = tempfile.mkstemp(suffix=".f90")
try:
with os.fdopen(fd, "w") as tmp:
tmp.write(
"program nested_if\n"
+ str("if (.true.) then\n" * levels)
+ str("end if\n" * levels)
+ "end program nested_if"
)
yield filename
finally:
os.remove(filename)


def test_recursion_error_handling(setup_tmp_file):
root = Path(setup_tmp_file).parent
request_string = write_rpc_request(1, "initialize", {"rootPath": str(root)})
errcode, results = run_request(request_string)
assert errcode == 0
assert results[0]["type"] == Severity.error

0 comments on commit f7c3ecd

Please sign in to comment.