Skip to content

Commit

Permalink
🐛 Fix error handling in LSP subprocesses
Browse files Browse the repository at this point in the history
  • Loading branch information
michprev committed Jun 11, 2024
1 parent 4ed0477 commit a633497
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
4 changes: 3 additions & 1 deletion wake/lsp/lsp_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ async def run(self, config: WakeConfig):
self.__svm = SolcVersionManager(config)
self.__compiler = SolidityCompiler(config)

# TODO process recovery?
self.__detectors_subprocess.process = multiprocessing.Process(
target=run_detectors_subprocess,
args=(
Expand Down Expand Up @@ -378,6 +377,9 @@ async def wait_subprocess_response(
except queue.Empty:
await asyncio.sleep(0.1)

if subprocess.process is not None and not subprocess.process.is_alive():
raise RuntimeError("Subprocess has terminated unexpectedly")

async def run_detector_callback(self, callback_id: str) -> List[CommandAbc]:
command_id = self.send_subprocess_command(
self.__detectors_subprocess,
Expand Down
50 changes: 23 additions & 27 deletions wake/lsp/subprocess_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ def run_detectors_thread(
config: WakeConfig,
ignored_detections_supported: bool,
command_id: int,
detector_names: List[str],
detectors_provider: LspProvider,
last_build: ProjectBuild,
last_build_info: ProjectBuildInfo,
Expand All @@ -199,6 +198,16 @@ def run_detectors_thread(
logging_buffer = []
logging_handler = LspLoggingHandler(logging_buffer)

# discover detectors
detector_names = run_detect.list_commands(
None, # pyright: ignore reportGeneralTypeIssues
plugin_paths={ # pyright: ignore reportGeneralTypeIssues
config.project_root_path / "detectors"
},
force_load_plugins=True, # pyright: ignore reportGeneralTypeIssues
verify_paths=False, # pyright: ignore reportGeneralTypeIssues
)

_, detections, detector_exceptions = detect(
detector_names,
last_build,
Expand Down Expand Up @@ -252,7 +261,6 @@ def run_printers_thread(
out_queue: multiprocessing.Queue,
config: WakeConfig,
command_id: int,
printer_names: List[str],
printers_provider: LspProvider,
last_build: ProjectBuild,
last_build_info: ProjectBuildInfo,
Expand All @@ -265,6 +273,15 @@ def run_printers_thread(
logging_buffer = []
logging_handler = LspLoggingHandler(logging_buffer)

printer_names = run_print.list_commands(
None, # pyright: ignore reportGeneralTypeIssues
plugin_paths={ # pyright: ignore reportGeneralTypeIssues
config.project_root_path / "printers"
},
force_load_plugins=True, # pyright: ignore reportGeneralTypeIssues
verify_paths=False, # pyright: ignore reportGeneralTypeIssues
)

with open(os.devnull, "w") as devnull:
console = Console(file=devnull)

Expand Down Expand Up @@ -382,17 +399,7 @@ def run_detectors_subprocess(
assert last_build_info is not None
assert last_graph is not None

# discover detectors
all_detectors = run_detect.list_commands(
None, # pyright: ignore reportGeneralTypeIssues
plugin_paths={ # pyright: ignore reportGeneralTypeIssues
config.project_root_path / "detectors"
},
force_load_plugins=True, # pyright: ignore reportGeneralTypeIssues
verify_paths=False, # pyright: ignore reportGeneralTypeIssues
)

detectors_thread = threading.Thread(
thread = threading.Thread(
target=run_detectors_thread,
args=(
[
Expand All @@ -404,15 +411,14 @@ def run_detectors_subprocess(
config,
ignored_detections_supported,
run_detectors_command_ids[-1],
all_detectors,
lsp_provider,
last_build,
last_build_info,
last_graph,
thread_event,
),
)
detectors_thread.start()
thread.start()

run_detectors = False
run_detectors_command_ids = []
Expand Down Expand Up @@ -488,16 +494,7 @@ def run_printers_subprocess(
assert last_build_info is not None
assert last_graph is not None

all_printers = run_print.list_commands(
None, # pyright: ignore reportGeneralTypeIssues
plugin_paths={ # pyright: ignore reportGeneralTypeIssues
config.project_root_path / "printers"
},
force_load_plugins=True, # pyright: ignore reportGeneralTypeIssues
verify_paths=False, # pyright: ignore reportGeneralTypeIssues
)

printers_thread = threading.Thread(
thread = threading.Thread(
target=run_printers_thread,
args=(
[
Expand All @@ -508,15 +505,14 @@ def run_printers_subprocess(
out_queue,
config,
run_printers_command_ids[-1],
all_printers,
lsp_provider,
last_build,
last_build_info,
last_graph,
thread_event,
),
)
printers_thread.start()
thread.start()

run_printers = False
run_printers_command_ids = []

0 comments on commit a633497

Please sign in to comment.