The ISO code errors report invalidity without the code #19

Closed
opened 2026-08-14 23:58:33 +00:00 by rosa · 0 comments
Owner

#13 replaced the crate's bare unit-struct errors with #[non_exhaustive] enums
on the grounds that a unit struct "discards the detail its operation had in
hand." ExchangeRateError::InvalidRate (src/exchange.rs:817) follows through
and carries the multiplier it turned away, printing it in the message. Two
errors got the enum but not the detail:

IsoAlphabeticCodeError::InvalidCode   // src/lib.rs:1230 — "invalid ISO 4217 alphabetic code"
IsoNumericCodeError::InvalidCode      // src/lib.rs:1239 — "invalid ISO 4217 numeric code"

Both are single-variant and payload-free. IsoAlphabeticCode::try_from("us")
(src/lib.rs:934) has the text in hand, discards it, and reports only that
something was invalid; TryFrom<[u8; 3]> (src/lib.rs:908) and
TryFrom<u32> (src/lib.rs:858) do the same with their inputs. A caller
reading a column of codes cannot say which one was at fault without threading
the input alongside the error.

The crate already has the other precedent: ParseMoneyError::UnknownCurrency
(src/parse.rs:324) keeps the offending text, and prints it.

Give both variants the input they rejected. The alphabetic code arrives as
&str in one path and [u8; 3] in the other, so a String field is the form
that suits both — at the cost of Copy, which IsoAlphabeticCodeError does not
currently derive anyway. The numeric one is a u32 and stays Copy.

The enum shape from #13 bought room for the detail; this is taking it.

Guideline: C-GOOD-ERR.

#13 replaced the crate's bare unit-struct errors with `#[non_exhaustive]` enums on the grounds that a unit struct "discards the detail its operation had in hand." `ExchangeRateError::InvalidRate` (`src/exchange.rs:817`) follows through and carries the multiplier it turned away, printing it in the message. Two errors got the enum but not the detail: ```rust IsoAlphabeticCodeError::InvalidCode // src/lib.rs:1230 — "invalid ISO 4217 alphabetic code" IsoNumericCodeError::InvalidCode // src/lib.rs:1239 — "invalid ISO 4217 numeric code" ``` Both are single-variant and payload-free. `IsoAlphabeticCode::try_from("us")` (`src/lib.rs:934`) has the text in hand, discards it, and reports only that something was invalid; `TryFrom<[u8; 3]>` (`src/lib.rs:908`) and `TryFrom<u32>` (`src/lib.rs:858`) do the same with their inputs. A caller reading a column of codes cannot say which one was at fault without threading the input alongside the error. The crate already has the other precedent: `ParseMoneyError::UnknownCurrency` (`src/parse.rs:324`) keeps the offending text, and prints it. Give both variants the input they rejected. The alphabetic code arrives as `&str` in one path and `[u8; 3]` in the other, so a `String` field is the form that suits both — at the cost of `Copy`, which `IsoAlphabeticCodeError` does not currently derive anyway. The numeric one is a `u32` and stays `Copy`. The enum shape from #13 bought room for the detail; this is taking it. Guideline: C-GOOD-ERR.
rosa closed this issue 2026-08-15 01:11:03 +00:00
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
rosa/lucre#19
No description provided.