A malformed pair does not say which side was malformed #28

Closed
opened 2026-08-15 04:17:35 +00:00 by rosa · 0 comments
Owner

read_currency (src/exchange/rate.rs:514) resolves one side of a pair's
notation and knows which side it is holding. Neither error it can return keeps
that: ParsePairError::Code passes the inner IsoAlphabeticCodeError along
untouched, and ParsePairError::UnknownCurrency carries the code alone
(src/exchange/rate.rs:544-550).

So "usd/EUR" and "USD/eur" are turned away in terms that differ only in the
text quoted back, and "ZZZ/EUR" reads exactly as "USD/ZZZ" would with the
codes swapped. A caller wanting to point at the offending half — underlining it
in a form field, say — has to match the quoted code against their own input to
work out which one it was.

Since #19 the content is all there; what is missing is the label. Both variants
are #[non_exhaustive], so a field can be added to either without breaking.

What it costs is the type to name the side with — a public Side { Base, Quote }
enum, small but permanent, or a bool that nobody should have to read. The
cheaper reading is to name the side only in the Display message and leave the
variants as they are, which helps a person and not a program.

Which of those is worth it is the decision here.

`read_currency` (`src/exchange/rate.rs:514`) resolves one side of a pair's notation and knows which side it is holding. Neither error it can return keeps that: `ParsePairError::Code` passes the inner `IsoAlphabeticCodeError` along untouched, and `ParsePairError::UnknownCurrency` carries the code alone (`src/exchange/rate.rs:544-550`). So `"usd/EUR"` and `"USD/eur"` are turned away in terms that differ only in the text quoted back, and `"ZZZ/EUR"` reads exactly as `"USD/ZZZ"` would with the codes swapped. A caller wanting to point at the offending half — underlining it in a form field, say — has to match the quoted code against their own input to work out which one it was. Since #19 the content is all there; what is missing is the label. Both variants are `#[non_exhaustive]`, so a field can be added to either without breaking. What it costs is the type to name the side with — a public `Side { Base, Quote }` enum, small but permanent, or a `bool` that nobody should have to read. The cheaper reading is to name the side only in the `Display` message and leave the variants as they are, which helps a person and not a program. Which of those is worth it is the decision here.
rosa closed this issue 2026-08-15 05:21:24 +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#28
No description provided.