Skip to content

Raise exceptions instead of calling sys.exit in decommutator - #55

Merged
joyvelasquez merged 8 commits into
mainfrom
fix/raise-exceptions-instead-of-sys-exit
Oct 6, 2026
Merged

joyvelasquez merged 8 commits into
mainfrom
fix/raise-exceptions-instead-of-sys-exit

Conversation

@joyvelasquez

@joyvelasquez joyvelasquez commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #45

Replaces sys.exit calls in the decommutator with raised exceptions that describe what went wrong and which file was involved. sys.exit() with no argument exits with code 0, so failures looked like successes to anything running these scripts. main.py is unchanged.

Each except: that led to an exit becomes except Exception as exc: and uses raise ... from exc, so the original error (for example, FileNotFoundError) stays in the traceback.

Progress

ccsds_reader_pipeline.py

  • file2bytestr: input file cannot be read → RuntimeError

swp_spc_l02l1.py (main)

  • Log file cannot be opened → RuntimeError
  • Leap second kernel not found or not loaded → RuntimeError
  • SCLK kernel not found or not loaded → RuntimeError
  • L1 CDF exists and overwrite is not set → FileExistsError
  • Could not check for or delete an existing L1 CDF → RuntimeError

This is not the final form: more specific exception classes can be added later, as noted in the issue.

@joyvelasquez joyvelasquez self-assigned this Oct 6, 2026
@joyvelasquez joyvelasquez added bug Something isn't working enhancement New feature or request refactor Code cleanup with no behavior change labels Oct 6, 2026
@joyvelasquez
joyvelasquez requested a review from namurphy October 6, 2026 00:52
@joyvelasquez

Copy link
Copy Markdown
Collaborator Author

@namurphy Ready for review. All sys.exit calls in ccsds_reader_pipeline.py and swp_spc_l02l1.py now raise exceptions with messages that name the file involved.

Comment on lines +83 to +84
msg = f"Could not read in file: {path}"
raise RuntimeError(msg) from exc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. This code follows the best practice of defining long exception messages prior to raising an exception with them. When this is not done, exceptions tracebacks get horrible-er.

Comment thread src/pyfaradaycup/decommutator/swp_spc_l02l1.py
Comment thread src/pyfaradaycup/decommutator/swp_spc_l02l1.py Outdated
msg = f"Could not check existence of or delete L1 CDF file: {l1path}"
statusmsg(
"\n***ERROR*** [swp_spc_l02l1] Could not check existence/delete L1 CDF file path. Exiting...\n",
f"***ERROR*** [swp_spc_l02l1] {msg}",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎗️ After switching to using logging (#50), we can replace the ***ERROR*** messages with a logger.error("...") so that users can have finer control over the verbosity that gets reported. That would be better in a later pull request, though.

@joyvelasquez
joyvelasquez merged commit 79f5d63 into main Oct 6, 2026
15 checks passed
@joyvelasquez
joyvelasquez deleted the fix/raise-exceptions-instead-of-sys-exit branch October 6, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request refactor Code cleanup with no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve exception handling in decommutator functionality

2 participants