FEAT: Propagate error messages from simulation methods to database#107
Open
mberz wants to merge 3 commits into
Open
FEAT: Propagate error messages from simulation methods to database#107mberz wants to merge 3 commits into
mberz wants to merge 3 commits into
Conversation
- Except explicitly raised error from the simulation methods and propagate them into the database - Except unexpected errors and add them to the log, propagate general error message ext
The model and schema for the error messages propagated from the simulation method
There was a problem hiding this comment.
Pull request overview
This PR adds end-to-end propagation of simulation error messages (including non-zero container exit codes and structured JSON errors) into persisted Simulation/SimulationRun records so the frontend can display meaningful failure reasons.
Changes:
- Detect non-zero simulation container exit codes and attempt to extract structured error messages from the result JSON.
- Persist
errorMessageonSimulationandSimulationRun, and expose it via Marshmallow schemas. - Extend
CloudExecutor’s completion stub to carry an exit code and return more informative logs.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| app/services/simulation_service.py | Adds exit-code checking, structured error extraction, and persists error messages on failures. |
| app/services/executors/cloud_executor.py | Tracks simulation failure via JSON "error" and surfaces an exit code through _CompletedJob. |
| app/schemas/simulation_schema.py | Exposes errorMessage in API responses for simulations and runs. |
| app/models/SimulationRun.py | Adds errorMessage column to persist run-level failures. |
| app/models/Simulation.py | Adds errorMessage column to persist simulation-level failures. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
447
to
+455
| def _poll_until_complete( | ||
| self, | ||
| remote_json_path: str, | ||
| local_uploads_dir: str, | ||
| remote_app_dir: str, | ||
| remote_sandbox_path: str, | ||
| remote_tar_path: Optional[str] = None, | ||
| ) -> bool: | ||
| """Adaptively poll the remote job until all results reach 100 % progress. | ||
| ) -> tuple[bool, int]: | ||
| """Adaptively poll the remote job until all results reach 100 % progress or an error occurs. |
Comment on lines
564
to
+571
| success = self._collect_outputs_and_cleanup( | ||
| remote_app_dir = remote_app_dir, | ||
| local_uploads_dir = local_uploads_dir, | ||
| remote_sandbox_path = remote_sandbox_path, | ||
| remote_tar_path = remote_tar_path, | ||
| ) | ||
|
|
||
| return success | ||
| return (success, 0) # Exit code 0 for success |
Comment on lines
+811
to
+827
| success, exit_code = self._poll_until_complete( | ||
| remote_json_path = f"{remote_app_dir_path}/{json_filename}", | ||
| local_uploads_dir = local_uploads_dir, | ||
| remote_app_dir = remote_app_dir_path, | ||
| remote_sandbox_path = f"{self.remote_work_dir}/{sandbox_name}", | ||
| remote_tar_path = f"{self.remote_work_dir}/{tar_image_name}", | ||
| ) | ||
|
|
||
| return _CompletedJob() | ||
| # Build log message | ||
| if exit_code != 0: | ||
| logs_output = f"Cloud job completed with error (exit code {exit_code})" | ||
| elif not success: | ||
| logs_output = "Cloud job completed but cleanup failed" | ||
| else: | ||
| logs_output = "Cloud job completed successfully" | ||
|
|
||
| return _CompletedJob(exit_code=exit_code, logs_output=logs_output) |
Comment on lines
482
to
486
| Returns: | ||
| bool: ``True`` if outputs were collected and the remote workspace | ||
| was cleaned up successfully; ``False`` if an error occurred | ||
| during :meth:`_collect_outputs_and_cleanup`. | ||
| tuple[bool, int]: A tuple of (success, exit_code) where: | ||
| - success: ``True`` if outputs were collected and cleaned up successfully | ||
| - exit_code: 0 for success, 1 for error in simulation | ||
| """ |
Comment on lines
+550
to
+554
| except RuntimeError as ex: | ||
| # These are errors explicitly raised in the simulation-method | ||
| # including a meaningful error message. | ||
| # Propagate error messages to the database (frontend). | ||
| error_msg = str(ex) |
Comment on lines
561
to
+565
| except Exception as ex: | ||
| # Unexpected errors - log full details but show generic message | ||
| import traceback | ||
|
|
||
| error_details = traceback.format_exc() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
Requires choras-org/simulation-backend#18 which introduces custom error classes for the simulation methods.