Skip to content

Commit 2ff5c3b

Browse files
committed
Raise exception in runner failed to start. Clean logs in CLI run.
1 parent 9cc0db6 commit 2ff5c3b

5 files changed

Lines changed: 34 additions & 16 deletions

File tree

finecode/logs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def save_logs_to_file(
5858
encoding="utf8",
5959
filter=filter_logs,
6060
)
61-
logger.info(f"Log file: {file_path}")
61+
logger.trace(f"Log file: {file_path}")
6262

6363

6464
def set_log_level_for_group(group: str, level: LogLevel | None):

finecode/workspace_manager/cli_app/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def get_projects_by_names(
9999
def find_projects_with_actions(
100100
ws_context: context.WorkspaceContext, actions: list[str]
101101
) -> dict[pathlib.Path, list[str]]:
102-
actions_by_project: dict[pathlib.Path, list[str]] = []
102+
actions_by_project: dict[pathlib.Path, list[str]] = {}
103103
actions_set = ordered_set.OrderedSet(actions)
104104

105105
for project in ws_context.ws_projects.values():

finecode/workspace_manager/logger_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def init_logger(trace: bool, stdout: bool = False):
1313
logger.remove()
1414
# disable logging raw messages
1515
# TODO: make configurable
16-
logger.configure(activation=[("pygls.protocol.json_rpc", False)])
16+
logger.configure(activation=[("pygls.protocol.json_rpc", False), ("pygls.feature_manager", False)])
1717
logs.save_logs_to_file(
1818
file_path=log_dir_path / "execution.log",
1919
log_level="TRACE" if trace else "INFO",

finecode/workspace_manager/lsp_server/services.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,23 @@ async def add_workspace_dir(
6161

6262
global_state.ws_context.ws_dirs_paths.append(dir_path)
6363
await read_configs.read_projects_in_dir(dir_path, global_state.ws_context)
64-
await runner_manager.update_runners(global_state.ws_context)
64+
try:
65+
await runner_manager.update_runners(global_state.ws_context)
66+
except runner_manager.RunnerFailedToStart:
67+
# user sees status in client(IDE), no need to raise explicit error
68+
...
6569
return schemas.AddWorkspaceDirResponse()
6670

6771

6872
async def delete_workspace_dir(
6973
request: schemas.DeleteWorkspaceDirRequest,
7074
) -> schemas.DeleteWorkspaceDirResponse:
7175
global_state.ws_context.ws_dirs_paths.remove(Path(request.dir_path))
72-
await runner_manager.update_runners(global_state.ws_context)
76+
try:
77+
await runner_manager.update_runners(global_state.ws_context)
78+
except runner_manager.RunnerFailedToStart:
79+
# user sees status in client(IDE), no need to raise explicit error
80+
...
7381
return schemas.DeleteWorkspaceDirResponse()
7482

7583

@@ -86,4 +94,8 @@ async def handle_changed_ws_dirs(added: list[Path], removed: list[Path]) -> None
8694
" but not found in ws context"
8795
)
8896

89-
await runner_manager.update_runners(global_state.ws_context)
97+
try:
98+
await runner_manager.update_runners(global_state.ws_context)
99+
except runner_manager.RunnerFailedToStart:
100+
# user sees status in client(IDE), no need to raise explicit error
101+
...

finecode/workspace_manager/runner/manager.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,18 @@ async def update_runners(ws_context: context.WorkspaceContext) -> None:
222222
runner.working_dir_path: runner for runner in extension_runners
223223
}
224224

225-
init_runners_coros = [
226-
_init_runner(
227-
runner, ws_context.ws_projects[runner.working_dir_path], ws_context
228-
)
229-
for runner in extension_runners
230-
]
231-
await asyncio.gather(*init_runners_coros)
225+
try:
226+
async with asyncio.TaskGroup() as tg:
227+
for runner in extension_runners:
228+
tg.create_task(
229+
_init_runner(
230+
runner, ws_context.ws_projects[runner.working_dir_path], ws_context
231+
)
232+
)
233+
except ExceptionGroup as eg:
234+
for exception in eg.exceptions:
235+
logger.exception(exception)
236+
raise RunnerFailedToStart("Failed to initialize runner")
232237

233238

234239
async def _init_runner(
@@ -250,7 +255,7 @@ async def _init_runner(
250255
project.status = domain.ProjectStatus.RUNNER_FAILED
251256
await notify_project_changed(project)
252257
runner.initialized_event.set()
253-
return
258+
raise RunnerFailedToStart(f"Runner failed to initialize: {error}")
254259

255260
try:
256261
await runner_client.notify_initialized(runner)
@@ -260,7 +265,8 @@ async def _init_runner(
260265
await notify_project_changed(project)
261266
runner.initialized_event.set()
262267
logger.exception(error)
263-
return
268+
raise RunnerFailedToStart(f"Runner failed to notify about initialization: {error}")
269+
264270
logger.debug("LSP Server initialized")
265271

266272
await read_configs.read_project_config(project=project, ws_context=ws_context)
@@ -278,7 +284,7 @@ async def _init_runner(
278284
project.status = domain.ProjectStatus.RUNNER_FAILED
279285
await notify_project_changed(project)
280286
runner.initialized_event.set()
281-
return
287+
raise RunnerFailedToStart(f"Runner failed to update config: {error}")
282288

283289
logger.debug(
284290
f"Updated config of runner {runner.working_dir_path},"

0 commit comments

Comments
 (0)