Skip to content

Commit 18acbb6

Browse files
authored
Merge pull request #14 from finecode-dev/feature/better-logging-and-error-handling
Improve logs and handle more errors
2 parents 2d7e070 + 1f8a3e8 commit 18acbb6

File tree

17 files changed

+61
-98
lines changed

17 files changed

+61
-98
lines changed

finecode_extension_runner/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ dependencies = [
1010
"tomlkit==0.11.*",
1111
"click==8.1.*",
1212
"pydantic==2.11.*",
13-
"platformdirs==4.3.*",
1413
"pygls==2.0.0-a6",
1514
"finecode_extension_api==0.3.*",
1615
"deepmerge==2.0.*",

finecode_extension_runner/src/finecode_extension_runner/_services/run_action.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from finecode_extension_runner import (
1616
partial_result_sender as partial_result_sender_module,
1717
)
18-
from finecode_extension_runner import project_dirs, run_utils, schemas
18+
from finecode_extension_runner import run_utils, schemas
1919
from finecode_extension_runner.di import resolver as di_resolver
2020

2121
last_run_id: int = 0
@@ -113,7 +113,10 @@ async def run_action(
113113

114114
# instantiate only on demand?
115115
project_path = project_def.path
116-
project_cache_dir = project_dirs.get_project_dir(project_path=project_path)
116+
project_cache_dir = project_path / ".venvs" / global_state.env_name / "cache"
117+
if not project_cache_dir.exists():
118+
project_cache_dir.mkdir()
119+
117120
action_context = code_action.ActionContext(
118121
project_dir=project_path, cache_dir=project_cache_dir
119122
)

finecode_extension_runner/src/finecode_extension_runner/app_dirs.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

finecode_extension_runner/src/finecode_extension_runner/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def start(
4747

4848
global_state.log_level = "INFO" if trace is False else "TRACE"
4949
global_state.project_dir_path = project_path
50+
global_state.env_name = env_name
5051
# asyncio.run(runner_start.start_runner())
5152

5253
# extension runner doesn't stop with async start after closing LS client(WM). Use

finecode_extension_runner/src/finecode_extension_runner/global_state.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
# the runner, not from updating the config
99
project_dir_path: Path | None = None
1010
log_level: Literal["TRACE", "INFO"] = "INFO"
11+
env_name: str = ""

finecode_extension_runner/src/finecode_extension_runner/lsp_server.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,9 @@ async def get_project_raw_config(
165165
return json.loads(raw_config.config)
166166

167167

168-
async def update_config(ls: lsp_server.LanguageServer, params):
169-
logger.trace(f"Update config: {params}")
168+
async def update_config(ls: lsp_server.LanguageServer, working_dir: pathlib.Path, project_name: str, config: dict[str, typing.Any]):
169+
logger.trace(f'Update config: {working_dir} {project_name} {config}')
170170
try:
171-
working_dir = params[0]
172-
project_name = params[1]
173-
config = params[2]
174171
actions = config["actions"]
175172
action_handler_configs = config["action_handler_configs"]
176173

@@ -225,14 +222,14 @@ def default(self, obj):
225222
return super().default(obj)
226223

227224

228-
async def run_action(ls: lsp_server.LanguageServer, params):
229-
logger.trace(f"Run action: {params[0]}")
230-
request = schemas.RunActionRequest(action_name=params[0], params=params[1])
231-
options = schemas.RunActionOptions(**params[2] if params[2] is not None else {})
225+
async def run_action(ls: lsp_server.LanguageServer, action_name: str, params: dict[str, typing.Any], options: dict[str, typing.Any] | None):
226+
logger.trace(f"Run action: {action_name}")
227+
request = schemas.RunActionRequest(action_name=action_name, params=params)
228+
options_schema = schemas.RunActionOptions(**options if options is not None else {})
232229
status: str = "success"
233230

234231
try:
235-
response = await services.run_action(request=request, options=options)
232+
response = await services.run_action(request=request, options=options_schema)
236233
except Exception as exception:
237234
if isinstance(exception, services.StopWithResponse):
238235
status = "stopped"
@@ -263,15 +260,15 @@ async def run_action(ls: lsp_server.LanguageServer, params):
263260
}
264261

265262

266-
async def reload_action(ls: lsp_server.LanguageServer, params):
267-
logger.trace(f"Reload action: {params}")
268-
services.reload_action(params[0])
263+
async def reload_action(ls: lsp_server.LanguageServer, action_name: str):
264+
logger.trace(f"Reload action: {action_name}")
265+
services.reload_action(action_name)
269266
return {}
270267

271268

272-
async def resolve_package_path(ls: lsp_server.LanguageServer, params):
273-
logger.trace(f"Resolve package path: {params}")
269+
async def resolve_package_path(ls: lsp_server.LanguageServer, package_name: str):
270+
logger.trace(f"Resolve package path: {package_name}")
274271
# TODO: handle properly ValueError
275-
result = services.resolve_package_path(params[0])
276-
logger.trace(f"Resolved {params[0]} to {result}")
272+
result = services.resolve_package_path(package_name)
273+
logger.trace(f"Resolved {package_name} to {result}")
277274
return {"packagePath": result}

finecode_extension_runner/src/finecode_extension_runner/project_dirs.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

finecode_extension_runner/src/finecode_extension_runner/services.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
context,
1717
domain,
1818
global_state,
19-
project_dirs,
2019
run_utils,
2120
schemas,
2221
)

src/finecode/cli_app/prepare_envs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,9 @@ async def check_or_recreate_all_dev_workspace_envs(
206206
project_def=current_project, env_name="dev_workspace", ws_context=ws_context
207207
)
208208
except runner_manager.RunnerFailedToStart as exception:
209-
# TODO
210-
raise exception
209+
raise PrepareEnvsFailed(
210+
f"Failed to start `dev_workspace` runner in {current_project.name}: {exception.message}"
211+
)
211212

212213
envs = []
213214

src/finecode/cli_app/run.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,12 @@ async def run_actions_in_running_project(
339339
ws_context=ws_context,
340340
result_format=services.RunResultFormat.STRING,
341341
)
342+
except services.ActionRunFailed as exception:
343+
raise RunFailed(f"Running of action {action_name} failed: {exception.message}")
342344
except Exception as error:
343-
# TODO: which are expected here?
344345
logger.error("Unexpected exception")
345346
logger.exception(error)
346-
raise RunFailed(f"Running of action {action_name} failed")
347+
raise RunFailed(f"Running of action {action_name} failed with unexpected exception")
347348

348349
run_result_str = run_result_to_str(run_result.result, action_name)
349350
result_by_action[action_name] = ActionRunResult(

0 commit comments

Comments
 (0)