Skip to content

Commit 869d4cb

Browse files
fix(mf2): Use correct error codes
1 parent a450b36 commit 869d4cb

File tree

5 files changed

+9
-10
lines changed

5 files changed

+9
-10
lines changed

packages/mf2-fluent/src/fluent.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,15 @@ const testCases: Record<string, TestCase> = {
272272
msg: 'plural',
273273
scope: {},
274274
exp: 'B',
275-
errors: ['$selector', 'bad-operand', 'not-selectable']
275+
errors: ['$selector', 'bad-operand', 'bad-selector']
276276
},
277277
{ msg: 'plural', scope: { selector: 1 }, exp: 'A' },
278278
{ msg: 'plural', scope: { selector: 2 }, exp: 'B' },
279279
{
280280
msg: 'plural',
281281
scope: { selector: 'one' },
282282
exp: 'B',
283-
errors: ['bad-operand', 'not-selectable']
283+
errors: ['bad-operand', 'bad-selector']
284284
},
285285
{
286286
msg: 'default',
@@ -667,7 +667,7 @@ describe('formatToParts', () => {
667667
expect(msg).toEqual([{ type: 'literal', value: 'Other' }]);
668668
expect(onError.mock.calls.map(args => args[0].type)).toEqual([
669669
'bad-operand',
670-
'not-selectable'
670+
'bad-selector'
671671
]);
672672
});
673673
});

packages/mf2-messageformat/src/cst/parse-cst.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function parseSelectMessage(
9595
const sel = parseExpression(ctx, pos);
9696
const body = sel.markup ?? sel.annotation;
9797
if (body && body.type !== 'function') {
98-
ctx.onError('bad-selector', body.start, body.end);
98+
ctx.onError('parse-error', body.start, body.end);
9999
}
100100
selectors.push(sel);
101101
pos = sel.end;

packages/mf2-messageformat/src/data-model/resolve-function-annotation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function resolveFunctionAnnotation(
2828

2929
const rf = ctx.functions[name];
3030
if (!rf) {
31-
throw new MessageError('missing-func', `Unknown function :${name}`);
31+
throw new MessageError('unknown-function', `Unknown function :${name}`);
3232
}
3333
const msgCtx = new MessageFunctionContext(ctx, source);
3434
const opt = resolveOptions(ctx, options);

packages/mf2-messageformat/src/errors.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { cst } from './data-model/from-cst.js';
88
*/
99
export class MessageError extends Error {
1010
type:
11-
| 'missing-func'
1211
| 'not-formattable'
12+
| 'unknown-function'
1313
| typeof MessageResolutionError.prototype.type
1414
| typeof MessageSelectionError.prototype.type
1515
| typeof MessageSyntaxError.prototype.type;
@@ -30,7 +30,6 @@ export class MessageSyntaxError extends MessageError {
3030
| 'empty-token'
3131
| 'bad-escape'
3232
| 'bad-input-expression'
33-
| 'bad-selector'
3433
| 'duplicate-declaration'
3534
| 'duplicate-option'
3635
| 'extra-content'
@@ -107,7 +106,7 @@ export class MessageResolutionError extends MessageError {
107106
* @beta
108107
*/
109108
export class MessageSelectionError extends MessageError {
110-
declare type: 'no-match' | 'not-selectable';
109+
declare type: 'bad-selector' | 'no-match';
111110
constructor(type: typeof MessageSelectionError.prototype.type) {
112111
super(type, `Selection error: ${type}`);
113112
}

packages/mf2-messageformat/src/select-pattern.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function selectPattern(context: Context, message: Message): Pattern {
1515
if (typeof selector.selectKey === 'function') {
1616
selectKey = selector.selectKey.bind(selector);
1717
} else {
18-
context.onError(new MessageSelectionError('not-selectable'));
18+
context.onError(new MessageSelectionError('bad-selector'));
1919
selectKey = () => null;
2020
}
2121
return {
@@ -70,7 +70,7 @@ export function selectPattern(context: Context, message: Message): Pattern {
7070
}
7171

7272
default:
73-
context.onError(new MessageSelectionError('not-selectable'));
73+
context.onError(new MessageSelectionError('bad-selector'));
7474
return [];
7575
}
7676
}

0 commit comments

Comments
 (0)