Skip to content

Commit 8355b3e

Browse files
committed
fix(cli,runtime): prevent duplicate traceback logging and improve error handling:
- Avoid double logging of exceptions by centralising traceback reporting in the CLI. - Runtime now raises clean errors while preserving original exception chaining.
1 parent 58c084a commit 8355b3e

2 files changed

Lines changed: 22 additions & 16 deletions

File tree

CodeEntropy/cli.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ def main() -> None:
3030
try:
3131
run_manager = CodeEntropyRunner(folder=folder)
3232
run_manager.run_entropy_workflow()
33-
except Exception as exc:
34-
logger.critical(
35-
"Fatal error during entropy calculation: %s", exc, exc_info=True
36-
)
37-
raise SystemExit(1) from exc
33+
except Exception:
34+
logger.exception("Fatal error during entropy calculation")
35+
raise SystemExit(1) from None

CodeEntropy/config/runtime.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,20 @@ def run_entropy_workflow(self) -> None:
222222
"""Run the end-to-end entropy workflow.
223223
224224
This method:
225-
- Sets up logging and prints the splash screen
226-
- Loads YAML config from CWD and parses CLI args
227-
- Merges args with YAML per-run config
228-
- Builds the MDAnalysis Universe (with optional force merging)
229-
- Validates user parameters
230-
- Constructs dependencies and executes EntropyWorkflow
231-
- Saves recorded console output to a log file
225+
- Sets up logging and prints the splash screen
226+
- Loads YAML config from CWD and parses CLI args
227+
- Merges args with YAML per-run config
228+
- Builds the MDAnalysis Universe (with optional force merging)
229+
- Validates user parameters
230+
- Constructs dependencies and executes EntropyWorkflow
231+
- Saves recorded console output to a log file
232+
- Logs run arguments if an error occurs to aid debugging
232233
233234
Raises:
234-
Exception: Re-raises any exception after logging with traceback.
235+
RuntimeError: If the workflow fails for any reason. The original
236+
exception is chained to preserve traceback information.
235237
"""
238+
args = None
236239
try:
237240
run_logger = self._logging_config.configure()
238241
self.show_splash()
@@ -288,9 +291,14 @@ def run_entropy_workflow(self) -> None:
288291

289292
self._logging_config.export_console()
290293

291-
except Exception as e:
292-
logger.error("CodeEntropyRunner encountered an error: %s", e, exc_info=True)
293-
raise
294+
except Exception as exc:
295+
if args is not None:
296+
try:
297+
logger.error("Run arguments at failure: %s", vars(args))
298+
except Exception:
299+
logger.error("Run arguments at failure could not be serialized")
300+
301+
raise RuntimeError("CodeEntropyRunner encountered an error") from exc
294302

295303
@staticmethod
296304
def _validate_required_args(args: Any) -> None:

0 commit comments

Comments
 (0)