Skip to content

Commit 058a6d6

Browse files
eemeliaphillips
andauthored
Clarify error & fallback handling (#879)
* Clarify error & fallback handling * Apply suggestions from code review Co-authored-by: Addison Phillips <[email protected]> * Select last rather than first attribute * Drop mention of "starting with Pattern Selection" * Attributes can't change the formatted output * Use "nor" instead of "or" regarding attribute restrictions --------- Co-authored-by: Addison Phillips <[email protected]>
1 parent aa8d293 commit 058a6d6

File tree

3 files changed

+59
-51
lines changed

3 files changed

+59
-51
lines changed

spec/errors.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Some examples include throwing an exception,
3232
returning an error code,
3333
or providing a function or method for enumerating any errors.
3434

35-
For all _messages_ without _Syntax Errors_ or _Data Model Errors_,
35+
For all _valid_ _messages_,
3636
an implementation MUST enable a user to get a formatted result.
3737
The formatted result might include _fallback values_
3838
such as when a _placeholder_'s _expression_ produced an error
@@ -52,7 +52,7 @@ and a _Resolution Error_ or a _Message Function Error_ MUST be emitted.
5252

5353
## Syntax Errors
5454

55-
**_<dfn>Syntax Errors</dfn>_** occur when the syntax representation of a message is not well-formed.
55+
**_<dfn>Syntax Errors</dfn>_** occur when the syntax representation of a message is not _well-formed_.
5656

5757
> Example invalid messages resulting in a _Syntax Error_:
5858
>
@@ -74,7 +74,7 @@ and a _Resolution Error_ or a _Message Function Error_ MUST be emitted.
7474
7575
## Data Model Errors
7676
77-
**_<dfn>Data Model Errors</dfn>_** occur when a message is invalid due to
77+
**_<dfn>Data Model Errors</dfn>_** occur when a message is not _valid_ due to
7878
violating one of the semantic requirements on its structure.
7979
8080
### Variant Key Mismatch

spec/formatting.md

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@ when formatting a message for display in a user interface, or for some later pro
77

88
To start, we presume that a _message_ has either been parsed from its syntax
99
or created from a data model description.
10-
If this construction has encountered any _Syntax Errors_ or _Data Model Errors_,
11-
an appropriate error MUST be emitted and a _fallback value_ MAY be used as the formatting result.
10+
If the resulting _message_ is not _well-formed_, a _Syntax Error_ is emitted.
11+
If the resulting _message_ is _well-formed_ but is not _valid_, a _Data Model Error_ is emitted.
1212

13-
Formatting of a _message_ is defined by the following operations:
13+
The formatting of a _message_ is defined by the following operations:
14+
15+
- **_<dfn>Pattern Selection</dfn>_** determines which of a message's _patterns_ is formatted.
16+
For a message with no _selectors_, this is simple as there is only one _pattern_.
17+
With _selectors_, this will depend on their resolution.
18+
19+
- **_<dfn>Formatting</dfn>_** takes the resolved values of the selected _pattern_,
20+
and produces the formatted result for the _message_.
21+
Depending on the implementation, this result could be a single concatenated string,
22+
an array of objects, an attributed string, or some other locally appropriate data type.
1423

1524
- **_<dfn>Expression and Markup Resolution</dfn>_** determines the value of an _expression_ or _markup_,
1625
with reference to the current _formatting context_.
@@ -24,6 +33,15 @@ Formatting of a _message_ is defined by the following operations:
2433
The resolution of _text_ is rather straightforward,
2534
and is detailed under _literal resolution_.
2635

36+
Implementations are not required to expose
37+
the _expression resolution_ and _pattern selection_ operations to their users,
38+
or even use them in their internal processing,
39+
as long as the final _formatting_ result is made available to users
40+
and the observable behavior of the _formatting_ matches that described here.
41+
42+
_Attributes_ MUST NOT have any effect on the formatted output of a _message_,
43+
nor be made available to function implementations.
44+
2745
> [!IMPORTANT]
2846
>
2947
> **This specification does not require either eager or lazy _expression resolution_ of _message_
@@ -39,27 +57,6 @@ Formatting of a _message_ is defined by the following operations:
3957
> have already been evaluated in the order in which the relevant _declarations_
4058
> and _selectors_ appear in the _message_.
4159
42-
- **_<dfn>Pattern Selection</dfn>_** determines which of a message's _patterns_ is formatted.
43-
For a message with no _selectors_, this is simple as there is only one _pattern_.
44-
With _selectors_, this will depend on their resolution.
45-
46-
At the start of _pattern selection_,
47-
if the _message_ contains any _reserved statements_,
48-
emit an _Unsupported Statement_ error.
49-
50-
- **_<dfn>Formatting</dfn>_** takes the resolved values of the selected _pattern_,
51-
and produces the formatted result for the _message_.
52-
Depending on the implementation, this result could be a single concatenated string,
53-
an array of objects, an attributed string, or some other locally appropriate data type.
54-
55-
Formatter implementations are not required to expose
56-
the _expression resolution_ and _pattern selection_ operations to their users,
57-
or even use them in their internal processing,
58-
as long as the final _formatting_ result is made available to users
59-
and the observable behavior of the formatter matches that described here.
60-
61-
_Attributes_ MUST NOT affect the processing or output of a _message_.
62-
6360
## Formatting Context
6461

6562
A message's **_<dfn>formatting context</dfn>_** represents the data and procedures that are required
@@ -82,8 +79,7 @@ At a minimum, it includes:
8279
- The _function registry_,
8380
providing the implementations of the functions referred to by message _functions_.
8481

85-
- Optionally, a fallback string to use for the message
86-
if it contains any _Syntax Errors_ or _Data Model Errors_.
82+
- Optionally, a fallback string to use for the message if it is not _valid_.
8783

8884
Implementations MAY include additional fields in their _formatting context_.
8985

@@ -192,8 +188,8 @@ If a _declaration_ exists for the _variable_, its resolved value is used.
192188
Otherwise, the _variable_ is an implicit reference to an input value,
193189
and its value is looked up from the _formatting context_ _input mapping_.
194190
195-
The resolution of a _variable_ MAY fail if no value is identified for its _name_.
196-
If this happens, an _Unresolved Variable_ error MUST be emitted.
191+
The resolution of a _variable_ fails if no value is identified for its _name_.
192+
If this happens, an _Unresolved Variable_ error is emitted.
197193
If a _variable_ would resolve to a _fallback value_,
198194
this MUST also be considered a failure.
199195
@@ -435,6 +431,17 @@ _Pattern selection_ is not supported for _fallback values_.
435431
436432
## Pattern Selection
437433
434+
If the _message_ contains any _reserved statements_,
435+
emit an _Unsupported Statement_ error.
436+
437+
If the _message_ being formatted is not _well-formed_ and _valid_,
438+
the result of pattern selection is a _pattern_ consisting of a single _fallback value_
439+
using the _message_'s fallback string defined in the _formatting context_
440+
or if this is not available or empty, the U+FFFD REPLACEMENT CHARACTER `�`.
441+
442+
If the _message_ being formatted does not contain a _matcher_,
443+
the result of pattern selection is its _pattern_ value.
444+
438445
When a _message_ contains a _matcher_ with one or more _selectors_,
439446
the implementation needs to determine which _variant_ will be used
440447
to provide the _pattern_ for the formatting operation.
@@ -504,11 +511,6 @@ This selection method is defined in more detail below.
504511
An implementation MAY use any pattern selection method,
505512
as long as its observable behavior matches the results of the method defined here.
506513
507-
If the message being formatted has any _Syntax Errors_ or _Data Model Errors_,
508-
the result of pattern selection MUST be a pattern resolving to a single _fallback value_
509-
using the message's fallback string defined in the _formatting context_
510-
or if this is not available or empty, the U+FFFD REPLACEMENT CHARACTER `�`.
511-
512514
### Resolve Selectors
513515
514516
First, resolve the values of each _selector_:
@@ -741,8 +743,8 @@ each _text_ and _placeholder_ part of the selected _pattern_ is resolved and for
741743
742744
Resolved values cannot always be formatted by a given implementation.
743745
When such an error occurs during _formatting_,
744-
an implementation MUST emit an appropriate _Message Function Error_ and use a
745-
_fallback value_ for the _placeholder_ with the error.
746+
an appropriate _Message Function Error_ is emitted and
747+
a _fallback value_ is used for the _placeholder_ with the error.
746748
747749
Implementations MAY represent the result of _formatting_ using the most
748750
appropriate data type or structure. Some examples of these include:
@@ -787,8 +789,9 @@ the _fallback value_ as a string,
787789
and a U+007D RIGHT CURLY BRACKET `}`.
788790
789791
> For example,
790-
> a message with a _Syntax Error_ and no fallback string
791-
> defined in the _formatting context_ would format to a string as `{�}`.
792+
> a _message_ that is not _well-formed_ would format to a string as `{�}`,
793+
> unless a fallback string is defined in the _formatting context_,
794+
> in which case that string would be used instead.
792795
793796
### Handling Bidirectional Text
794797

spec/syntax.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Attempting to parse a _message_ that is not _well-formed_ will result in a _Synt
9090
A _message_ is **_<dfn>valid</dfn>_** if it is _well-formed_ and
9191
**also** meets the additional content restrictions
9292
and semantic requirements about its structure defined below for
93-
_declarations_, _matcher_, _options_, and _attributes_.
93+
_declarations_, _matcher_, and _options_.
9494
Attempting to parse a _message_ that is not _valid_ will result in a _Data Model Error_.
9595

9696
## The Message
@@ -368,14 +368,18 @@ and at least one _variant_.
368368
When the _matcher_ is processed, the result will be a single _pattern_ that serves
369369
as the template for the formatting process.
370370

371-
A _message_ can only be considered _valid_ if the following requirements are
372-
satisfied:
371+
A _message_ can only be considered _valid_ if the following requirements are satisfied;
372+
otherwise, a corresponding _Data Model Error_ will be produced during processing:
373373

374-
- The number of _keys_ on each _variant_ MUST be equal to the number of _selectors_.
375-
- At least one _variant_ MUST exist whose _keys_ are all equal to the "catch-all" key `*`.
376-
- Each _selector_ MUST have an _annotation_,
374+
- _Variant Key Mismatch_:
375+
The number of _keys_ on each _variant_ MUST be equal to the number of _selectors_.
376+
- _Missing Fallback Variant_:
377+
At least one _variant_ MUST exist whose _keys_ are all equal to the "catch-all" key `*`.
378+
- _Missing Selector Annotation_:
379+
Each _selector_ MUST have an _annotation_,
377380
or contain a _variable_ that directly or indirectly references a _declaration_ with an _annotation_.
378-
- Each _variant_ MUST use a list of _keys_ that is unique from that
381+
- _Duplicate Variant_:
382+
Each _variant_ MUST use a list of _keys_ that is unique from that
379383
of all other _variants_ in the _message_.
380384
_Literal_ _keys_ are compared by their contents, not their syntactical appearance.
381385

@@ -587,7 +591,8 @@ Multiple _options_ are permitted in an _annotation_.
587591
_Options_ are separated from the preceding _function_ _identifier_
588592
and from each other by whitespace.
589593
Each _option_'s _identifier_ MUST be unique within the _annotation_:
590-
an _annotation_ with duplicate _option_ _identifiers_ is not _valid_.
594+
an _annotation_ with duplicate _option_ _identifiers_ is not _valid_
595+
and will produce a _Duplicate Option Name_ error during processing.
591596
592597
The order of _options_ is not significant.
593598
@@ -750,10 +755,10 @@ by an U+003D EQUALS SIGN `=` along with optional whitespace.
750755
751756
Multiple _attributes_ are permitted in an _expression_ or _markup_.
752757
Each _attribute_ is separated by whitespace.
753-
Each _attribute_'s _identifier_ MUST be unique within the _expression_ or _markup_:
754-
an _expression_ or _markup_ with duplicate _attribute_ _identifiers_ is not _valid_.
755758
756-
The order of _attributes_ is not significant.
759+
Each _attribute_'s _identifier_ SHOULD be unique within the _expression_ or _markup_:
760+
all but the last _attribute_ with the same _identifier_ are ignored.
761+
The order of _attributes_ is not otherwise significant.
757762
758763
```abnf
759764
attribute = "@" identifier [[s] "=" [s] literal]

0 commit comments

Comments
 (0)