Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report errors from Functions and Intl objects #398

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions fluent/src/builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* `FluentType`. Functions must return `FluentType` objects as well.
*/

import { FluentNone, FluentNumber, FluentDateTime } from "./types.js";
import { FluentNumber, FluentDateTime } from "./types.js";

function merge(argopts, opts) {
return Object.assign({}, argopts, values(opts));
Expand All @@ -27,22 +27,18 @@ function values(opts) {

export
function NUMBER([arg], opts) {
if (arg instanceof FluentNone) {
return arg;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep this ...

if (arg instanceof FluentNumber) {
return new FluentNumber(arg.valueOf(), merge(arg.opts, opts));
}
return new FluentNone("NUMBER()");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was introduced in April in 24355cf to provide better fallback values. Today we can simply throw :)


throw new TypeError("Invalid argument type to NUMBER");
}

export
function DATETIME([arg], opts) {
if (arg instanceof FluentNone) {
return arg;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and this ...

if (arg instanceof FluentDateTime) {
return new FluentDateTime(arg.valueOf(), merge(arg.opts, opts));
}
return new FluentNone("DATETIME()");

throw new TypeError("Invalid argument type to DATETIME");
}
8 changes: 4 additions & 4 deletions fluent/src/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function resolveExpression(scope, expr) {
function VariableReference(scope, {name}) {
if (!scope.args || !scope.args.hasOwnProperty(name)) {
if (scope.insideTermReference === false) {
scope.reportError(new ReferenceError(`Unknown variable: ${name}`));
scope.reportError(new ReferenceError(`Unknown variable: $${name}`));
}
return new FluentNone(`$${name}`);
}
Expand All @@ -151,7 +151,7 @@ function VariableReference(scope, {name}) {
}
default:
scope.reportError(
new TypeError(`Unsupported variable type: ${name}, ${typeof arg}`)
new TypeError(`Variable type not supported: $${name}, ${typeof arg}`)
);
return new FluentNone(`$${name}`);
}
Expand Down Expand Up @@ -224,8 +224,8 @@ function FunctionReference(scope, {name, args}) {

try {
return func(...getArguments(scope, args));
} catch (e) {
// XXX Report errors.
} catch (err) {
scope.reportError(err);
return new FluentNone(`${name}()`);
}
}
Expand Down
8 changes: 4 additions & 4 deletions fluent/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export class FluentNumber extends FluentType {
Intl.NumberFormat, this.opts
);
return nf.format(this.value);
} catch (e) {
// XXX Report the error.
} catch (err) {
scope.reportError(err);
return this.value;
}
}
Expand All @@ -83,8 +83,8 @@ export class FluentDateTime extends FluentType {
Intl.DateTimeFormat, this.opts
);
return dtf.format(this.value);
} catch (e) {
// XXX Report the error.
} catch (err) {
scope.reportError(err);
return this.value;
}
}
Expand Down
Loading