Skip to content

Commit

Permalink
Backed out changeset 41722eea7dd5 (bug 1623778) for causing failures …
Browse files Browse the repository at this point in the history
…in l10n/test/mochitest/localization/test_format

CLOSED TREE
  • Loading branch information
Mihai Alexandru Michis committed Mar 21, 2020
1 parent 5e6056c commit 650ff15
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 51 deletions.
12 changes: 1 addition & 11 deletions intl/l10n/FluentBundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "FluentBundle.h"
#include "nsContentUtils.h"
#include "mozilla/dom/UnionTypes.h"
#include "unicode/numberformatter.h"
#include "unicode/datefmt.h"
Expand Down Expand Up @@ -103,16 +102,7 @@ void FluentBundle::AddResource(
FluentResource& aResource,
const dom::FluentBundleAddResourceOptions& aOptions) {
bool allowOverrides = aOptions.mAllowOverrides;
nsTArray<nsCString> errors;

fluent_bundle_add_resource(mRaw.get(), aResource.Raw(), allowOverrides,
&errors);

for (auto& err : errors) {
nsContentUtils::LogSimpleConsoleError(NS_ConvertUTF8toUTF16(err), "L10n",
false, true,
nsIScriptError::warningFlag);
}
fluent_bundle_add_resource(mRaw.get(), aResource.Raw(), allowOverrides);
}

bool FluentBundle::HasMessage(const nsACString& aId) {
Expand Down
65 changes: 25 additions & 40 deletions intl/l10n/rust/fluent-ffi/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,29 @@ pub unsafe extern "C" fn fluent_bundle_format_pattern(
let mut errors = vec![];
let value = bundle.format_pattern(pattern, args.as_ref(), &mut errors);
ret_val.assign(value.as_bytes());
append_fluent_errors_to_ret_errors(ret_errors, &errors);
for error in errors {
match error {
FluentError::ResolverError(ref err) => match err {
ResolverError::Reference(ref s) => {
let error = format!("ReferenceError: {}", s);
ret_errors.push((&error).into());
}
ResolverError::MissingDefault => {
let error = "RangeError: No default";
ret_errors.push(error.into());
}
ResolverError::Cyclic => {
let error = "RangeError: Cyclic reference";
ret_errors.push(error.into());
}
ResolverError::TooManyPlaceables => {
let error = "RangeError: Too many placeables";
ret_errors.push(error.into());
}
},
_ => panic!("Unknown error!"),
}
}
true
}

Expand All @@ -222,15 +244,14 @@ pub unsafe extern "C" fn fluent_bundle_add_resource(
bundle: &mut FluentBundleRc,
r: &FluentResource,
allow_overrides: bool,
ret_errors: &mut ThinVec<nsCString>,
) {
// we don't own the resource
let r = mem::ManuallyDrop::new(Rc::from_raw(r));

if allow_overrides {
bundle.add_resource_overriding(Rc::clone(&r));
} else if let Err(errors) = bundle.add_resource(Rc::clone(&r)) {
append_fluent_errors_to_ret_errors(ret_errors, &errors);
} else if bundle.add_resource(Rc::clone(&r)).is_err() {
eprintln!("Error while adding a resource");
}
}

Expand All @@ -251,39 +272,3 @@ fn convert_args<'a>(ids: &'a [String], arg_vals: &'a [FluentArgument]) -> Option
}
Some(args)
}

fn append_fluent_errors_to_ret_errors(ret_errors: &mut ThinVec<nsCString>, errors: &[FluentError]) {
for error in errors {
match error {
FluentError::ResolverError(ref err) => match err {
ResolverError::Reference(ref s) => {
let error = format!("[fluent] ReferenceError: {}.", s);
ret_errors.push(error.into());
}
ResolverError::MissingDefault => {
let error = "[fluent] RangeError: No default value for selector.";
ret_errors.push(error.into());
}
ResolverError::Cyclic => {
let error = "[fluent] RangeError: Cyclic reference encountered while resolving a message.";
ret_errors.push(error.into());
}
ResolverError::TooManyPlaceables => {
let error = "[fluent] RangeError: Too many placeables in a message.";
ret_errors.push(error.into());
}
},
FluentError::Overriding { kind, id } => {
let error = format!("[fluent] OverrideError: An entry {} of type {} is already defined in this bundle.", id, kind);
ret_errors.push(error.into());
}
FluentError::ParserError(pe) => {
let error = format!(
"[fluent] ParserError: Error of kind {:#?} in position: ({}, {})",
pe.kind, pe.pos.0, pe.pos.1
);
ret_errors.push(error.into());
}
}
}
}

0 comments on commit 650ff15

Please sign in to comment.