mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 1623778 - Improve error reporting for AddResource. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D67695 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
1aa5b504ca
commit
7f4b927d9e
@ -5,6 +5,7 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#include "FluentBundle.h"
|
#include "FluentBundle.h"
|
||||||
|
#include "nsContentUtils.h"
|
||||||
#include "mozilla/dom/UnionTypes.h"
|
#include "mozilla/dom/UnionTypes.h"
|
||||||
#include "unicode/numberformatter.h"
|
#include "unicode/numberformatter.h"
|
||||||
#include "unicode/datefmt.h"
|
#include "unicode/datefmt.h"
|
||||||
@ -102,7 +103,16 @@ void FluentBundle::AddResource(
|
|||||||
FluentResource& aResource,
|
FluentResource& aResource,
|
||||||
const dom::FluentBundleAddResourceOptions& aOptions) {
|
const dom::FluentBundleAddResourceOptions& aOptions) {
|
||||||
bool allowOverrides = aOptions.mAllowOverrides;
|
bool allowOverrides = aOptions.mAllowOverrides;
|
||||||
fluent_bundle_add_resource(mRaw.get(), aResource.Raw(), allowOverrides);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FluentBundle::HasMessage(const nsACString& aId) {
|
bool FluentBundle::HasMessage(const nsACString& aId) {
|
||||||
|
@ -213,29 +213,7 @@ pub unsafe extern "C" fn fluent_bundle_format_pattern(
|
|||||||
let mut errors = vec![];
|
let mut errors = vec![];
|
||||||
let value = bundle.format_pattern(pattern, args.as_ref(), &mut errors);
|
let value = bundle.format_pattern(pattern, args.as_ref(), &mut errors);
|
||||||
ret_val.assign(value.as_bytes());
|
ret_val.assign(value.as_bytes());
|
||||||
for error in errors {
|
append_fluent_errors_to_ret_errors(ret_errors, &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
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,14 +222,15 @@ pub unsafe extern "C" fn fluent_bundle_add_resource(
|
|||||||
bundle: &mut FluentBundleRc,
|
bundle: &mut FluentBundleRc,
|
||||||
r: &FluentResource,
|
r: &FluentResource,
|
||||||
allow_overrides: bool,
|
allow_overrides: bool,
|
||||||
|
ret_errors: &mut ThinVec<nsCString>,
|
||||||
) {
|
) {
|
||||||
// we don't own the resource
|
// we don't own the resource
|
||||||
let r = mem::ManuallyDrop::new(Rc::from_raw(r));
|
let r = mem::ManuallyDrop::new(Rc::from_raw(r));
|
||||||
|
|
||||||
if allow_overrides {
|
if allow_overrides {
|
||||||
bundle.add_resource_overriding(Rc::clone(&r));
|
bundle.add_resource_overriding(Rc::clone(&r));
|
||||||
} else if bundle.add_resource(Rc::clone(&r)).is_err() {
|
} else if let Err(errors) = bundle.add_resource(Rc::clone(&r)) {
|
||||||
eprintln!("Error while adding a resource");
|
append_fluent_errors_to_ret_errors(ret_errors, &errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,3 +251,39 @@ fn convert_args<'a>(ids: &'a [String], arg_vals: &'a [FluentArgument]) -> Option
|
|||||||
}
|
}
|
||||||
Some(args)
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user