Skip to content

Commit dc5601d

Browse files
fix(mf2): Do not fallback on all :number and :datetime option resolution errors
1 parent 4bb0fdc commit dc5601d

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

mf2/fluent/src/fluent.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const testCases: Record<string, TestCase> = {
9191
{
9292
msg: 'num-fraction-bad',
9393
scope: { arg: 1234 },
94-
exp: '{$arg}',
94+
exp: '1,234',
9595
errors: ['bad-option']
9696
},
9797
{ msg: 'num-style', scope: { arg: 1234 }, exp: '123,400%' },

mf2/messageformat/src/functions/datetime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const datetime = (
6868
}
6969
} catch {
7070
const msg = `Value ${value} is not valid for :datetime option ${name}`;
71-
throw new MessageResolutionError('bad-option', msg, ctx.source);
71+
ctx.onError(new MessageResolutionError('bad-option', msg, ctx.source));
7272
}
7373
}
7474

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { MessageFormat } from '../index.js';
2+
3+
test('soft fail for integer options', () => {
4+
const mf = new MessageFormat('en', '{42 :number minimumFractionDigits=foo}');
5+
const onError = jest.fn();
6+
expect(mf.format(undefined, onError)).toEqual('42');
7+
expect(onError.mock.calls).toMatchObject([[{ type: 'bad-option' }]]);
8+
});

mf2/messageformat/src/functions/number.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export function number(
105105
}
106106
} catch {
107107
const msg = `Value ${optval} is not valid for :number option ${name}`;
108-
throw new MessageResolutionError('bad-option', msg, source);
108+
ctx.onError(new MessageResolutionError('bad-option', msg, source));
109109
}
110110
}
111111

0 commit comments

Comments
 (0)