-
-
Notifications
You must be signed in to change notification settings - Fork 35
Add error handling #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add error handling #320
Changes from 2 commits
1a27ccd
4389ae5
55890b9
99ce4a1
da1ecaf
4d8c753
2e1f943
38e33ad
8e12260
22866fd
d46856f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,71 @@ the local variable takes precedence. | |
|
||
It is an error for a local variable definition to | ||
refer to a local variable that's defined after it in the message. | ||
|
||
## Error Handling | ||
|
||
During the formatting of a message, | ||
various errors may be encountered. | ||
These are divided to the following categories: | ||
|
||
- **Syntax errors** occur when the syntax representation of a message is invalid. | ||
- **Resolution errors** occur when the runtime value of a part of a message | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is unclear what this means. Can we say "function resolution"?
We already have unresolved as a class of errors a bit below. So what about we call this section "Function resolution"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The difference between the "resolution" and "formatting" errors that's proposed here is perhaps best seen by considering how a Placeholder containing an Expression is handled. Let's say that we have something like
or
where During the formatting of this, the custom code could then emit two different sorts of errors:
Would you agree that these are different error categories, and that this categorical split could lead to different error handling in user code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If If no In any case, I think I would move this item below some of the others here (perhaps to the bottom of the list), since I find myself thinking that this could also mean unresolved or formatting error when in fact this error would probably only occur later (only when the pattern is syntactically correct and all of the variables and functions have been resolved but there is still a problem). Or am I still not understanding? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both The intent here is to allow for a custom formatting function to emit two different kinds of errors: Resolution and Formatting. This is meant to enable something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: I don't think what I am saying here affects the spec, but the answer above. I think it is contradicting:
It is unclear what is the difference between the two: "get the value" and "resolve variable reference" But that implementation detail should not "leak" in the kind of error I am getting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please note that the syntax example for the above discussion is this placeholder:
The
eemeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cannot be determined. | ||
|
||
eemeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- **Unresolved Variable** errors occur when a variable reference cannot be resolved. | ||
eemeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- **Selection errors** cover failures encountered during selection. | ||
eemeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- **Selector errors** are failures in the matching of a key to a specific selector. | ||
eemeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- **Missing Fallback** errors occur when no Variant is selected | ||
eemeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
due to the message not including a Variant with only catch-all keys. | ||
|
||
- **Formatting errors** occur during the formatting of a resolved value, | ||
for example when encountering a value with an unsupported type | ||
or an internally inconsistent set of options. | ||
eemeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
During selection, an expression handler must only emit Resolution and Selection errors. | ||
eemeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
During formatting, an expression handler must only emit Resolution and Formatting errors. | ||
|
||
In all cases, when encountering an error, | ||
a message formatter must provide some representation of the message. | ||
An informative error or errors must also be separately provided. | ||
eemeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
When an error occurs in the syntax or resolution of an Expression or MarkupStart Option, | ||
the Expression or MarkupStart in question is processed as if the option was not defined. | ||
eemeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This may allow for the fallback handling described below to be avoided, | ||
though an error must still be emitted. | ||
|
||
When an error occurs within a Selector, | ||
the selector must not match any VariantKey other than the catch-all `*` | ||
and a Selector error is emitted. | ||
When selection fails to match any Variant, | ||
an empty string is used as the formatted string representation of the message | ||
and a Missing Fallback error is emitted. | ||
eemeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
When an error occurs in a Placeholder that is being formatted, | ||
the fallback string representation of the Placeholder | ||
always starts with U+007B LEFT CURLY BRACKET `{` | ||
and ends with U+007D RIGHT CURLY BRACKET `}`. | ||
Comment on lines
+210
to
+211
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we might have a bidi consideration here? If the string being formatted is in Arabic, we might emit an FSI before the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be covered by the text in PR #315? The intent there is to define a prefix and a suffix to a part's formatted string representation, which here would be something like |
||
Between the brackets, the following contents are used: | ||
|
||
- Expression with Literal Operand: U+0028 LEFT PARENTHESIS `(` | ||
followed by the value of the Literal, | ||
and then by U+0029 RIGHT PARENTHESIS `)` | ||
eemeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- Expression with Variable Operand: U+0024 DOLLAR SIGN `$` | ||
followed by the Variable Name of the Operand | ||
- Expression with no Operand: U+003A COLON `:` followed by the Expression Name | ||
- Markup start: U+002B PLUS SIGN `+` followed by the MarkupStart Name | ||
- Markup end: U+002D HYPHEN-MINUS `-` followed by the MarkupEnd Name | ||
- Otherwise: Three U+003F QUESTION MARK `?` characters, i.e. `???` | ||
eemeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
For example, the formatted string representation of the expression `{$foo :bar}` | ||
would be `{$foo}` if the variable could not be resolved. | ||
eemeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The formatted string representation of a message with an unrecoverable syntax error | ||
eemeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
is the concatenation of U+007B LEFT CURLY BRACKET `{`, | ||
a string identifier for the message, | ||
and U+007D RIGHT CURLY BRACKET `}`. | ||
If an identifier is not available, | ||
eemeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
it is replaced with three U+003F QUESTION MARK `?` characters, | ||
resulting in the string `{???}`. | ||
eemeli marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.