Skip to content

Commit b9f0886

Browse files
committed
More clarification on the various flavors of format error.
1 parent bd74a4a commit b9f0886

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

fluent-bundle/src/bundle.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,28 @@ impl<'bundle> FluentBundle<'bundle> {
281281
///
282282
/// # Errors
283283
///
284-
/// If the message id or path is not found in the bundle, `format`
285-
/// returns None. On Fluent processing errors after initial lookup
286-
/// `format` returns `Some((path, errors)`. `path` is the path you
287-
/// originally provided, and `errors` explains what went wrong.
284+
/// If no message is found at `path`, then `format` returns `None`.
285+
///
286+
/// In all other cases, `format` returns a string even if it
287+
/// encountered errors. `format` uses two fallback techniques to
288+
/// create the fallback string. If there are bad references in the
289+
/// message, then they will be substituted with `'___'`. If there
290+
/// are more extensive errors, then `format` will fall back to using
291+
/// `path` itself as the formatted string. Sometimes, but not always,
292+
/// these partial failures will emit extra error information in the
293+
/// second term of the return tuple.
294+
///
295+
/// ```
296+
/// use fluent::bundle::FluentBundle;
297+
///
298+
/// // Create a message with bad cyclic reference
299+
/// let mut bundle = FluentBundle::new(&["en-US"]);
300+
/// bundle.add_messages("foo = a { foo } b");
301+
///
302+
/// // The result falls back to "___"
303+
/// let value = bundle.format("foo", None);
304+
/// assert_eq!(value, Some(("___".to_string(), vec![])));
305+
/// ```
288306
pub fn format(
289307
&self,
290308
path: &str,

0 commit comments

Comments
 (0)