Skip to content

Commit f80ee6d

Browse files
committed
fix: apply code review suggestions from PR #98
- Use model_dump_json(indent=2) instead of model_dump() + json.dumps() to correctly serialize Pydantic models with non-standard types - Split OSError handling in _import_project into FileNotFoundError and generic OSError to avoid broken error messages from wrapping OSError in FileNotFoundError
1 parent 6ee1418 commit f80ee6d

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

th_cli/commands/project.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,14 +438,12 @@ def _export_project(sync_apis: SyncApis, id: int, output_file: str | None) -> No
438438
except UnexpectedResponse as e:
439439
handle_api_error(e, f"export project ID '{id}'")
440440

441-
export_data = project_create.model_dump()
442-
443441
if not output_file:
444442
safe_name = "".join(c if c.isalnum() or c in "-_" else "_" for c in (project_create.name or f"project-{id}"))
445443
output_file = f"{safe_name}-project-config.json"
446444

447445
try:
448-
Path(output_file).write_text(json.dumps(export_data, indent=2))
446+
Path(output_file).write_text(project_create.model_dump_json(indent=2))
449447
click.echo(colorize_success(f"Project {id} exported to '{output_file}'"))
450448
except OSError as e:
451449
raise CLIError(f"Failed to write export file '{output_file}': {e}")
@@ -455,8 +453,10 @@ def _import_project(sync_apis: SyncApis, file: str) -> None:
455453
"""Import a project config from a JSON file"""
456454
try:
457455
file_bytes = Path(file).read_bytes()
456+
except FileNotFoundError as e:
457+
handle_file_error(e, "import file")
458458
except OSError as e:
459-
handle_file_error(FileNotFoundError(e), "import file")
459+
raise CLIError(f"Failed to read import file '{file}': {e}")
460460

461461
body = BodyImportprojectConfigApiV1ProjectsImportPost(import_file=file_bytes)
462462

0 commit comments

Comments
 (0)