55 * and are not a part of the library's public API.
66 */
77
8- import { MessageResolutionError } from '../errors.ts' ;
8+ import { MessageFunctionError } from '../errors.ts' ;
99import type { MessageValue } from '../message-value.ts' ;
1010import type { MessageFunctionContext } from '../resolve/function-context.ts' ;
1111import { asPositiveInteger , asString } from './utils.ts' ;
@@ -60,7 +60,7 @@ function testFunction(
6060 }
6161 if ( typeof input !== 'number' ) {
6262 const msg = 'Input is not numeric' ;
63- throw new MessageResolutionError ( 'bad-operand' , msg , source ) ;
63+ throw new MessageFunctionError ( 'bad-operand' , msg , source ) ;
6464 }
6565 const value : number = input ; // Otherwise TS complains in callbacks
6666
@@ -71,7 +71,7 @@ function testFunction(
7171 else throw 1 ;
7272 } catch {
7373 const msg = `Invalid option decimalPlaces=${ options . decimalPlaces } ` ;
74- throw new MessageResolutionError ( 'bad-option' , msg , source ) ;
74+ throw new MessageFunctionError ( 'bad-option' , msg , source ) ;
7575 }
7676 }
7777 if ( 'fails' in options ) {
@@ -94,7 +94,7 @@ function testFunction(
9494 }
9595 } catch {
9696 const msg = `Invalid option fails=${ options . fails } ` ;
97- onError ( new MessageResolutionError ( 'bad-option' , msg , source ) ) ;
97+ onError ( new MessageFunctionError ( 'bad-option' , msg , source ) ) ;
9898 }
9999 }
100100
@@ -106,7 +106,10 @@ function testFunction(
106106 } ,
107107 selectKey : opt . canSelect
108108 ? keys => {
109- if ( opt . failsSelect ) throw new Error ( 'Selection failed' ) ;
109+ if ( opt . failsSelect ) {
110+ const msg = 'Selection failed' ;
111+ throw new MessageFunctionError ( 'bad-option' , msg , source ) ;
112+ }
110113 if ( value === 1 ) {
111114 if ( opt . decimalPlaces === 1 && keys . has ( '1.0' ) ) return '1.0' ;
112115 if ( keys . has ( '1' ) ) return '1' ;
@@ -116,14 +119,20 @@ function testFunction(
116119 : undefined ,
117120 toParts : opt . canFormat
118121 ? ( ) => {
119- if ( opt . failsFormat ) throw new Error ( 'Formatting failed' ) ;
122+ if ( opt . failsFormat ) {
123+ const msg = 'Formatting failed' ;
124+ throw new MessageFunctionError ( 'bad-option' , msg , source ) ;
125+ }
120126 const parts = Array . from ( testParts ( value , opt . decimalPlaces ) ) ;
121127 return [ { type : 'test' , locale : 'und' , parts } ] ;
122128 }
123129 : undefined ,
124130 toString : opt . canFormat
125131 ? ( ) => {
126- if ( opt . failsFormat ) throw new Error ( 'Formatting failed' ) ;
132+ if ( opt . failsFormat ) {
133+ const msg = 'Formatting failed' ;
134+ throw new MessageFunctionError ( 'bad-option' , msg , source ) ;
135+ }
127136 const parts = Array . from ( testParts ( value , opt . decimalPlaces ) ) ;
128137 return parts . map ( part => part . value ) . join ( '' ) ;
129138 }
0 commit comments