Comments (4)
I asked on rust user group - https://users.rust-lang.org/t/l10n-library-api-question/19967
from fluent-rs.
I agree with the general direction. Thanks for writing this down.
In our conversation, you mentioned using Option<Result<String, (String, Vec<FluentError>)>>
for the return type of format
. I have an open question about using Result
in our APIs like that. Its purpose is to provide a branching mechanism. But format
doesn't really branch on errors, it always returns something which is good to be used.
Using Result
can lead to duplicated code:
if let Some(resolved) = bundle.format("key") {
resolved
// Handle value.
.and_then(|value| ...)
// Handle value again, and possibly errors.
.or_else(|(value, errs)| ...)
}
If instead format
returned Option<(String, Option<Vec<FluentError>>)>>
, this code could be simplified to:
if let Some((value, errs)) = bundle.format("key") {
// Handle errors.
errs.and_then(|errs| ...);
// Handle value.
value
}
I don't know what the established pattern for such scenarios is in Rust. Is it better to have a dedicated branch for the error scenario with fallback (or_else
) or to handle errors separately if there are Some
?
from fluent-rs.
I also realized that using Option
might prove to be limiting when we want to differentiate between bundle-level errors. E.g. there could be a different error for when a message is missing, a different one for when the id starts with a -
(because terms are private), and yet another one when the message exists but doesn't have a value!
Taking this into account, maybe we should return one of the following types?
Result<Result<String, (String, Vec<ResolveError>)>, BundleError>
, orResult<(String, Vec<ResolveError>), BundleError>
, orResult<(String, Option<Vec<ResolveError>>), BundleError>
from fluent-rs.
This has been fixed by 21f3a31
from fluent-rs.
Related Issues (20)
- ResourceManager::get_bundle and get_bundles is inconsistent and confusing
- ResourceManager ignores and hides errors
- ResourceManager needs to implement BundleGenerator HOT 2
- Parser swallows leading whitespace after indented placeable HOT 2
- Clippy should be run in CI HOT 2
- rustmt should be run in CI
- error[E0277]: `(dyn Any + 'static)` cannot be sent between threads safely HOT 11
- Cannot use built-in functions HOT 2
- Which data providers Fluent crates use? HOT 3
- Make FluentArgs a trait? HOT 1
- Switching windows process/thread ui languages HOT 2
- Provide Way to Avoid Allocating To Collect Formatting Errors HOT 7
- Using or switching to icu4x crates? HOT 4
- Output looks the same, but is different HOT 3
- Behaviour of FluentArgs::set is misleading HOT 1
- Support full precision of all numbers HOT 1
- How to use this in a command line program and properly parse POSIX locales? HOT 1
- [Feature request] Allow serialize all AST types instead of just Resource HOT 7
- Include source position in the AST HOT 5
- Does a 'safe harbor' release of the current HEAD make sense before further changes? HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluent-rs.