Repository navigation
Catch specific exceptions instead of using bare except - #69
Merged
Merged
Conversation
Remove unused verbose, ptp, and ccsds_head parameters from private helper functions, along with unreachable code after raise statements, unused variables, and commented-out code. Keep verbose on _cdf35e_35f so that main can call each CDF writer with the same arguments, and include the failing key in its RuntimeError message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace every bare except in the decommutator with the exceptions that can be expected at that point, and give the resulting errors messages that say what failed, chaining the original exception. Where any error should be reported, catch Exception with a generic message. Fix main catching the string "CDFError", which raised TypeError instead of catching spacepy.pycdf.CDFError. Document the important exceptions in docstrings, and remove the two items in the decommutator README that this addresses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # src/pyfaradaycup/decommutator/ccsds_reader_pipeline.py # src/pyfaradaycup/decommutator/swp_spc_l02l1.py
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.
Replaces every bare
except:insrc/pyfaradaycup/decommutator/with the exceptions that can be expected at that point. The resulting errors now have messages that say what failed, and they chain the original exception.Note
This branch is based on #67, so it includes that commit until #67 is merged. The change for this PR is the last commit.
Bug fix
mainhadexcept "CDFError":, which catches a string. In Python 3, that line raisesTypeErrorwhenever any exception reaches it. A CDF that could not be created therefore crashed the run with a confusing error instead of being logged and skipped. It now catchesspacepy.pycdf.CDFError.ccsds_reader_pipeline.pytry/exceptaroundpkt_inds[:, 0](3 places) is replaced with an explicit check for an empty array.SC_HKfile inread_file_sc:ValueErrorandKeyErrorfrom the packet header, and includes the reason in the printed message.StopIterationandKeyErrorwhen falling back to the date in the path._parse_pkt:ValueErrorfor packets that are too short.RuntimeErrornaming the mnemonic and APID that could not be decoded. Theseraisestatements previously had no message._get_layoutand_get_layout_sc:OSErrorwhen reading the.blkfile.ValueErrorwhen parsing it, and raiseRuntimeErrorwith the file name, line number, and line._get_layoutno longer tries to open the same file twice.swp_spc_l02l1.pymain:Exceptionwhen filling a CDF and logs the exception with the APID. It still moves on to the next APID.RuntimeErrorwith the file name._cdf35e_35fand_cdf351_353_354:CDFError,TypeError,ValueError) raiseRuntimeErrorwith the variable name._cdf352:ValueError) and variables that cannot be written are still logged and skipped, now with the reason.except Exceptionwith a generic message._get_newest_kernel: when no kernel files are found, the error now names the file pattern and directory.Documentation
Raisessections to:main_get_layoutand_get_layout_sc_cdf35e_35f,_cdf351_353_354, and_cdf352mainthat errors for a single APID are logged and skipped, and that a partly filled CDF may be left behind.except:blocks" and "Raise exceptions with messages" items from the decommutatorREADME.md.Testing
pre-commit run --all-filespasses.nox -s tests-3.9andnox -s tests-3.14pass.nox -s docsbuilds with--nitpicky --fail-on-warning._get_layout_scerror paths for a missing file and a malformed line, plus_wrapper_statuson a file with no packets, by calling them directly.🤖 Generated with Claude Code