Skip to content

Commit fa60b0f

Browse files
committed
Refactor errors, adding section for Message Function Errors
1 parent 0e1304b commit fa60b0f

File tree

3 files changed

+62
-39
lines changed

3 files changed

+62
-39
lines changed

spec/errors.md

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ and MUST be emitted as soon as possible.
1616
The other error categories are only emitted during formatting,
1717
but it might be possible to detect them with validation tools.
1818

19-
During selection, an _expression_ handler MUST only emit _Resolution Errors_ and _Selection Errors_.
20-
During formatting, an _expression_ handler MUST only emit _Resolution Errors_ and _Formatting Errors_.
19+
During selection and formatting,
20+
_expression_ handlers MUST only emit _Message Function Errors_.
2121

22-
_Resolution Errors_ and _Formatting Errors_ in _expressions_ that are not used
22+
_Resolution Errors_ and _Message Function Errors_ in _expressions_ that are not used
2323
in _pattern selection_ or _formatting_ MAY be ignored,
2424
as they do not affect the output of the formatter.
2525

@@ -34,7 +34,7 @@ SHOULD prioritise _Syntax Errors_ and _Data Model Errors_ over others.
3434

3535
When an error occurs within a _selector_,
3636
the _selector_ MUST NOT match any _variant_ _key_ other than the catch-all `*`
37-
and a _Resolution Error_ or a _Selection Error_ MUST be emitted.
37+
and a _Resolution Error_ or a _Message Function Error_ MUST be emitted.
3838

3939
## Syntax Errors
4040

@@ -241,49 +241,72 @@ or for private implementation use that is not supported by the current implement
241241
> * {{The value is not one.}}
242242
> ```
243243
244-
### Invalid Expression
244+
### Unsupported Statement
245+
246+
An **_<dfn>Unsupported Statement</dfn>_** error occurs when a message includes a _reserved statement_.
247+
248+
> For example, attempting to format this message
249+
> would always result in an _Unsupported Statement_ error:
250+
>
251+
> ```
252+
> .some {|horse|}
253+
> {{The message body}}
254+
> ```
255+
256+
## Message Function Errors
245257
246-
An **_<dfn>Invalid Expression</dfn>_** error occurs when a _message_ includes an _expression_
258+
### Bad Expression
259+
260+
A **_<dfn>Bad Expression</dfn>_** error occurs when a _message_ includes an _expression_
247261
whose implementation-defined internal requirements produce an error during _function resolution_
248262
or when a _function_ returns a value (such as `null`) that the implementation does not support.
249263
250-
An **_<dfn>Operand Mismatch Error</dfn>_** is an _Invalid Expression_ error that occurs when
264+
> For example, the following _message_ might produce a _Bad Expression_ error if the
265+
> the function `:function` threw an exception or otherwise emitted an error
266+
> rather than returning a valid value:
267+
>
268+
> ```
269+
> This has a bad expression {$var :function} because it has a bug in it.
270+
> ```
271+
272+
### Bad Operand
273+
274+
A **_<dfn>Bad Operand</dfn>_** error is an error that occurs when
251275
an _operand_ provided to a _function_ during _function resolution_ does not match one of the
252276
expected implementation-defined types for that function;
253277
or in which a literal _operand_ value does not have the required format
254278
and thus cannot be processed into one of the expected implementation-defined types
255279
for that specific _function_.
256280
257-
> For example, the following _message_ produces an _Operand Mismatch Error_
258-
> (a type of _Invalid Expression_ error)
281+
> For example, the following _message_ produces a _Bad Operand_ error
259282
> because the literal `|horse|` does not match the production `number-literal`,
260283
> which is a requirement of the function `:number` for its operand:
284+
>
261285
> ```
262286
> .local $horse = {horse :number}
263287
> {{You have a {$horse}.}}
264288
> ```
265-
> The following _message_ might produce an _Invalid Expression_ error if the
266-
> the function `:function` threw an exception or otherwise emitted an error
267-
> rather than returning a valid value:
268-
>```
269-
> {{This has an invalid expression {$var :function} because it has a bug in it.}}
270-
>```
271289
272-
### Unsupported Statement
290+
### Bad Option
273291
274-
An **_<dfn>Unsupported Statement</dfn>_** error occurs when a message includes a _reserved statement_.
292+
A **_<dfn>Bad Option</dfn>_** error is an error that occurs when
293+
an _option_ value provided to a _function_ during _function resolution_ does not match one of the
294+
expected implementation-defined types for that function;
295+
or in which a literal _option_ value does not have the required format
296+
and thus cannot be processed into one of the expected implementation-defined types
297+
for that specific _function_.
275298
276-
> For example, attempting to format this message
277-
> would always result in an _Unsupported Statement_ error:
299+
> For example, the following _message_ might produce a _Bad Option_ error
300+
> because the literal `foo` does not match the production `number-literal`,
301+
> which is a requirement of the function `:number` for its `minimumFractionDigits` _option_:
278302
>
279303
> ```
280-
> .some {|horse|}
281-
> {{The message body}}
304+
> The answer is {42 :number minimumFractionDigits=foo}.
282305
> ```
283306
284-
## Selection Errors
307+
### Selection Error
285308
286-
**_<dfn>Selection Errors</dfn>_** occur when message selection fails.
309+
A **_<dfn>Selection Error</dfn>_** occurs when message selection fails.
287310
288311
> For example, attempting to format either of the following messages
289312
> might result in a _Selection Error_ if done within a context that
@@ -302,9 +325,9 @@ An **_<dfn>Unsupported Statement</dfn>_** error occurs when a message includes a
302325
> * {{The value is not one.}}
303326
> ```
304327
305-
## Formatting Errors
328+
### Formatting Error
306329
307-
**_<dfn>Formatting Errors</dfn>_** occur during the formatting of a resolved value,
330+
A **_<dfn>Formatting Error</dfn>_** occurs during the formatting of a resolved value,
308331
for example when encountering a value with an unsupported type
309332
or an internally inconsistent set of options.
310333

spec/formatting.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ the following steps are taken:
250250
argument type `T` and return type `U`
251251
for implementations of functions
252252
such that `U` can be coerced to `T`.
253-
Implementations of a _function_ SHOULD emit an
254-
_Invalid Expression_ error for _operands_ whose resolved value
253+
Implementations of a _function_ SHOULD emit a
254+
_Bad Operand_ error for _operands_ whose resolved value
255255
or type is not supported.
256256
257257
> [!NOTE]
@@ -307,13 +307,13 @@ the following steps are taken:
307307
resolve the value of the _expression_ as the result of that function call.
308308
309309
If the call fails or does not return a valid value,
310-
emit a _Invalid Expression_ error.
310+
emit a _Message Function Error_.
311311
312312
Implementations MAY provide a mechanism for the _function_ to provide
313313
additional detail about internal failures.
314314
Specifically, if the cause of the failure was that the datatype, value, or format of the
315315
_operand_ did not match that expected by the _function_,
316-
the _function_ might cause an _Operand Mismatch Error_ to be emitted.
316+
the _function_ might cause a _Bad Operand_ error to be emitted.
317317
318318
In all failure cases, use the _fallback value_ for the _expression_ as the resolved value.
319319
@@ -519,7 +519,7 @@ First, resolve the values of each _selector_:
519519
1. Else:
520520
1. Let `nomatch` be a resolved value for which selection always fails.
521521
1. Append `nomatch` as the last element of the list `res`.
522-
1. Emit a _Selection Error_.
522+
1. Emit a _Message Function Error_.
523523
524524
The form of the resolved values is determined by each implementation,
525525
along with the manner of determining their support for selection.
@@ -735,7 +735,7 @@ each _text_ and _placeholder_ part of the selected _pattern_ is resolved and for
735735
736736
Resolved values cannot always be formatted by a given implementation.
737737
When such an error occurs during _formatting_,
738-
an implementation SHOULD emit a _Formatting Error_ and produce a
738+
an implementation SHOULD emit a _Message Function Error_ and produce a
739739
_fallback value_ for the _placeholder_ that produced the error.
740740
A formatting function MAY substitute a value to use instead of a _fallback value_.
741741

spec/registry.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ The function `:string` provides string selection and formatting.
288288
The _operand_ of `:string` is either any implementation-defined type
289289
that is a string or for which conversion to a string is supported,
290290
or any _literal_ value.
291-
All other values produce an _Invalid Expression_ error.
291+
All other values produce a _Bad Operand_ error.
292292
293293
> For example, in Java, implementations of the `java.lang.CharSequence` interface
294294
> (such as `java.lang.String` or `java.lang.StringBuilder`),
@@ -600,7 +600,7 @@ The _function_ `:integer` performs selection as described in [Number Selection](
600600
601601
The _operand_ of a number function is either an implementation-defined type or
602602
a literal whose contents match the `number-literal` production in the [ABNF](/spec/message.abnf).
603-
All other values produce an _Invalid Expression_ error.
603+
All other values produce a _Bad Operand_ error.
604604
605605
> For example, in Java, any subclass of `java.lang.Number` plus the primitive
606606
> types (`byte`, `short`, `int`, `long`, `float`, `double`, etc.)
@@ -776,15 +776,15 @@ If no options are specified, this function defaults to the following:
776776
The _operand_ of the `:datetime` function is either
777777
an implementation-defined date/time type
778778
or a _date/time literal value_, as defined in [Date and Time Operand](#date-and-time-operands).
779-
All other _operand_ values produce an _Invalid Expression_ error.
779+
All other _operand_ values produce a _Bad Operand_ error.
780780
781781
#### Options
782782
783783
The `:datetime` function can use either the appropriate _style options_
784784
or can use a collection of _field options_ (but not both) to control the formatted
785785
output.
786786
787-
If both are specified, an _Invalid Expression_ error MUST be emitted
787+
If both are specified, a _Bad Option_ error MUST be emitted
788788
and a _fallback value_ used as the resolved value of the _expression_.
789789
790790
> [!NOTE]
@@ -901,7 +901,7 @@ If no options are specified, this function defaults to the following:
901901
The _operand_ of the `:date` function is either
902902
an implementation-defined date/time type
903903
or a _date/time literal value_, as defined in [Date and Time Operand](#date-and-time-operands).
904-
All other _operand_ values produce an _Invalid Expression_ error.
904+
All other _operand_ values produce a _Bad Operand_ error.
905905
906906
#### Options
907907
@@ -924,7 +924,7 @@ If no options are specified, this function defaults to the following:
924924
The _operand_ of the `:time` function is either
925925
an implementation-defined date/time type
926926
or a _date/time literal value_, as defined in [Date and Time Operand](#date-and-time-operands).
927-
All other _operand_ values produce an _Invalid Expression_ error.
927+
All other _operand_ values produce a _Bad Operand_ error.
928928
929929
#### Options
930930
@@ -941,7 +941,7 @@ The function `:time` has these _options_:
941941
The _operand_ of a date/time function is either
942942
an implementation-defined date/time type
943943
or a _date/time literal value_, as defined below.
944-
All other _operand_ values produce an _Invalid Expression_ error.
944+
All other _operand_ values produce a _Bad Operand_ error.
945945
946946
A **_<dfn>date/time literal value</dfn>_** is a non-empty string consisting of an ISO 8601 date,
947947
or an ISO 8601 datetime optionally followed by a timezone offset.
@@ -963,7 +963,7 @@ For more information, see [Working with Timezones](https://w3c.github.io/timezon
963963
> The [ABNF](/spec/message.abnf) and [syntax](/spec/syntax.md) of MF2
964964
> do not formally define date/time literals.
965965
> This means that a _message_ can be syntactically valid but produce
966-
> an _Operand Mismatch Error_ at runtime.
966+
> a _Bad Operand_ error at runtime.
967967
968968
> [!NOTE]
969969
> String values passed as variables in the _formatting context_'s

0 commit comments

Comments
 (0)