Replace runtime String errors with a typed L10nError#28
Merged
Conversation
Introduce L10nError, a #[non_exhaustive] runtime error enum re-exported
from the crate root and the prelude. It carries owned strings rather than
fluent-bundle's own error types, so it stays stable across fluent-bundle
updates (the same decoupling goal as the road-to-1.0 work).
The runtime API now returns Result<_, L10nError> instead of
Result<_, String>:
- L10nBundle::{new, new_without_isolation, msg, attr, msg_segments}
- L10nLanguageVec::{load, load_without_isolation}
- the generated L10nLanguage::new
- the generated compressed L10n::{load, load_all} accessors, whose
user decompressor error is wrapped in L10nError::Decompression
Generated code only `.unwrap()`/`?`-es these results, so message.rs needs
no change; the template and the compressed-accessor generator carry the
new signature. Regenerated every committed *_gen.rs fixture, refreshed the
insta snapshots (only the `new` signature line changed), and regenerated
the playground outputs. Strengthened the runtime test to match
L10nError::MessageNotFound rather than just asserting is_err().
Third of the batched 0.7 breaking changes; version already at 0.7.0.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Third of the batched 0.7 breaking changes on the road to 1.0 (road-to-1.0 item #3; version already at 0.7.0).
What & why
The runtime API returned
Result<_, String>everywhere — impossible to match on, and a 1.0 wart. This introducesL10nError, a#[non_exhaustive]enum re-exported from the crate root and the prelude, and switches the whole runtime surface to it:L10nBundle::{new, new_without_isolation, msg, attr, msg_segments}L10nLanguageVec::{load, load_without_isolation}L10nLanguage::newL10n::{load, load_all}accessors — the user's decompressor still returnsResult<_, String>, and its error is wrapped inL10nError::DecompressionIt mirrors the
BuildErrorwork already done on the build side. Crucially, the variants carry owned strings, not fluent-bundle's error types, so this public enum doesn't churn when that pre-1.0 dependency is bumped — the same decoupling the road-to-1.0 plan calls for.This is breaking only for code that matched on / compared the error
String. Code thatunwrap/?-ed is unaffected — which is why the generated accessors (all.unwrap()) needed no body changes.Notable mechanics
*_gen.rstest modules are compiled, and theirL10nLanguage::newdoesL10nBundle::new(...)?— so oncenewreturnsL10nError, the staleStringversions wouldn't compile (noString: From<L10nError>), which would block the very test run that regenerates them. I pre-applied the exact signature change, then let the tests regenerate and confirmed the only content diff is thenew()line.cargo insta accept); verified the aggregate diff across 15 snapshots is only the signature line.single_gzip_l10n.rs).L10nError::MessageNotFound { id }instead of just.is_err().Verification (local, all green)
cargo test --features build,langneg— 100 unit + 1 playground integration testcargo fmt --all --check,cargo clippy --all-targets --features build,langneg -- -D warningsRUSTDOCFLAGS="-D warnings" cargo doc --no-deps --features build,langnegcargo build --benches --features bench-internalsScope note
impl FromStr for L10nstill usestype Err = String(a generated enum-parse on a generated type, distinct from the runtime error path) — left as-is to keep this focused.Remaining 0.7 work
L10nLanguageVec::get, generatedload()/load_all()unwraps).🤖 Generated with Claude Code