Skip to content

Commit 06fa917

Browse files
committed
More clarification on the various flavors of format error.
1 parent 9ba419d commit 06fa917

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

fluent/src/bundle.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,28 @@ impl<'bundle> FluentBundle<'bundle> {
297297
///
298298
/// # Errors
299299
///
300-
/// If the message id or path is not found in the bundle, `format`
301-
/// returns None. On Fluent processing errors after initial lookup
302-
/// `format` returns `Some((path, errors)`. `path` is the path you
303-
/// originally provided, and `errors` explains what went wrong.
300+
/// If no message is found at `path`, then `format` returns `None`.
301+
///
302+
/// In all other cases, `format` returns a string even if it
303+
/// encountered errors. `format` uses two fallback techniques to
304+
/// create the fallback string. If there are bad references in the
305+
/// message, then they will be substituted with `'___'`. If there
306+
/// are more extensive errors, then `format` will fall back to using
307+
/// `path` itself as the formatted string. Sometimes, but not always,
308+
/// these partial failures will emit extra error information in the
309+
/// second term of the return tuple.
310+
///
311+
/// ```
312+
/// use fluent::bundle::FluentBundle;
313+
///
314+
/// // Create a message with bad cyclic reference
315+
/// let mut bundle = FluentBundle::new(&["en-US"]);
316+
/// bundle.add_messages("foo = a { foo } b");
317+
///
318+
/// // The result falls back to "___"
319+
/// let value = bundle.format("foo", None);
320+
/// assert_eq!(value, Some(("___".to_string(), vec![])));
321+
/// ```
304322
pub fn format(
305323
&self,
306324
path: &str,

0 commit comments

Comments
 (0)