replace unwrap() with error propagation across anise/src#693
replace unwrap() with error propagation across anise/src#693themouli wants to merge 1 commit intonyx-space:masterfrom
Conversation
36ce5a1 to
4889667
Compare
There was a problem hiding this comment.
Code Review
This pull request replaces numerous instances of .unwrap() with .expect() or proper error handling throughout the codebase to improve robustness and error reporting. The review identified several areas for further improvement, including optimizing cloning operations in lookup table access, eliminating redundant parsing in file persistence, and correcting misleading variable naming in DER encoding logic.
| impl Encode for LookUpTable { | ||
| fn encoded_len(&self) -> der::Result<der::Length> { | ||
| let (ids, names, id_entries, name_entries) = self.der_encoding(); | ||
| let (ids, names, id_entries, name_entries) = self.der_encoding()?; |
There was a problem hiding this comment.
The destructuring of the tuple returned by der_encoding() has the names and id_entries variables swapped relative to the tuple's actual order (ids, id_entries, names, name_entries). While the subsequent addition in encoded_len is commutative and thus correct, the variable naming is misleading and could lead to bugs in future modifications.
| let (ids, names, id_entries, name_entries) = self.der_encoding()?; | |
| let (ids, id_entries, names, name_entries) = self.der_encoding()?; |
There was a problem hiding this comment.
Out of scope — the variable naming is pre-existing on master. My PR only added ? for error propagation, didn't touch the destructure or encode order.
|
|
||
| fn encode(&self, encoder: &mut impl Writer) -> der::Result<()> { | ||
| let (ids, names, id_entries, name_entries) = self.der_encoding(); | ||
| let (ids, names, id_entries, name_entries) = self.der_encoding()?; |
There was a problem hiding this comment.
The variable names in this destructuring are swapped relative to the tuple returned by der_encoding(). This results in the names variable holding id_entries data and vice versa. Although they are encoded in the correct sequence (matching the Decode implementation), the naming is highly confusing for maintainers.
| let (ids, names, id_entries, name_entries) = self.der_encoding()?; | |
| let (ids, id_entries, names, name_entries) = self.der_encoding()?; |
There was a problem hiding this comment.
Out of scope — the variable naming is pre-existing on master. My PR only added ? for error propagation, didn't touch the destructure or encode order.
4889667 to
7d6a7ca
Compare
Summary
Replaced
unwrap()calls throughoutanise/src/with proper error propagation (?) orexpect()carrying a meaningful invariant message where the call is provably infallible. Addresses #679 (follow-up to #677).Improvements
unwrap()with?propagation across the almanac, ephemerides, DAF, KPL, orientations, structure, and math modules so failures surface with typed errors instead of panicking.Somecheck,valid_up_toon UTF-8 decoding, a Keplerian-constructor contract), theunwrap()is replaced withexpect("...")documenting why it cannot fail — making future debugging and audits easier.DAF::persistnow returnsResult<(), DAFError>instead ofio::Result<()>, so I/O errors carry the file path / action context and decoding failures propagate cleanly. Breaking change for external callers ofpersist.Bug Fixes
#679
Testing and validation
cargo check --all-targetsclean (pre-existing pyo3 deprecation warnings only).DAF::persistand the KPL parser would be welcome if desired.