Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions exploration/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,20 @@ In both languages, built-in error handling assumes a singular error.
ICU4X operates in low resource environments for which returning at most 1 error is desirable
because returning more than 1 error would require heap allocation.
* Programming conventions and idioms: in [feedback from ICU-TC](https://docs.google.com/document/d/11yJUWedBIpmq-YNSqqDfgUxcREmlvV0NskYganXkQHA/edit#bookmark=id.lx4ls9eelh99),
they found over the 25 years of maintaining the library that there was more cost than benefit in providing a default best effort return value at the same time as providing error information.
The additional constraint in ICU4C's C++ style to return an error code rather than throwing errors using the STL further complicates the usefulness and likelihood to be used correctly during nested calls.
they found over the 25 years of maintaining the library that there was more cost than benefit in additionally providing error information with a default best effort return value compared to just returning the default best effort value.
The additional constraint in ICU4C's C++ style to return an error code rather than throwing errors using the STL further complicates the usefulness and likelihood to be used correctly by developers, especially during nested calls.

> [!NOTE]
> The wording in this document uses the word "signal" in regards to providing
> information about an error rather than "return" or "emit" when referring to
> a requirement that an implementation must at least indicate that an error has
> occurred.
> The word "signal" better accomodates more alternatives in the solution space
> like those that only choose to indicate that an error occurred,
> while still including those that additionally prefer to return the error
> itself as an error object.
> (By contrast, "return an error" implies that an error object will be thrown or
> returned, and "emit an error" is ambiguous as to what is or isn't performed.)

## Proposed Design

Expand Down Expand Up @@ -83,6 +95,33 @@ This alternative establishes constraints that would contravene the constraints t
* execution environment constraints
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What execution environment constraints does this alternative contravene? The only such mentioned in this document is that the cost of returning more than one error may be prohibitive in some cases, and the current text explicitly says "error or errors" to allow for an implementation signaling a single error to be valid.

Suggested change
* execution environment constraints

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text says "an informative error". As written, that implies to me an error object, like a java.lang.Throwable instance. Despite discussion in last week's meeting to interpret that phrase as equivalent to "whether or not an error occurred", it comes across distinctly as something more and thus should be rewritten if the intent is not so. There are applications like ICU and potentially browsers that might only want to provide a best effort message and signal an error, but not pay the cost of creating "informative error" objects each time.

As I mentioned in the 2024-04-09 meeting, another paradigm from which to look at this, besides "whether is returning an error possible", is "how actionable is returning the error object". ICU & browsers need to be performant and might not want to pay the cost of the creating a full error object.

* experience-based programming guidelines

For example, in ICU,
[the suggested practice](https://docs.google.com/document/d/11yJUWedBIpmq-YNSqqDfgUxcREmlvV0NskYganXkQHA/edit#bookmark=id.lx4ls9eelh99)
is to avoid additionally returning optional error codes when providing best-effort formatted results.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This applies to all solutions that require a runtime error to be signalled in some way, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point here is that if you're already returning a best-effort result from a formatter, then in ICU, it hasn't been useful to deal with the ErrorCodes altogether because the calling code is not looking for it. So for ICU, trying to use the ErrorCode in such cases is optional at best, but confusing and hard to reason about at worst. There's no benefit to dealing with the ErrorCode in these cases. And that's the general approach they arrived at over time dealing with formatter code. That's my interpretation & recollection of the linked discussion.

Those ICU guidelines seems reasonable for ICU, since ICU can't fail so it has to return something. Assuming "solution" = MF2 implementation, then yes, it seems reasonable and generally applicable advice for other implementations, although the guidelines that make sense to other implementations depend on each of their designs & use cases.

The fact that the current spec text takes a strong universal stance on what implementations must do, when that doesn't actually fit all use cases / guidelines / PLs, is still the crux of the matter.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By "solution" I meant the choice of spec language that we are debating here.

As I understand it (and please do correct me if I'm wrong), the ICU experience-based programming guideline in this case is roughly speaking, "You should not report formatting errors if you can fallback to some formatted result."

My point here is that this guideline applies to all spec text choices which require an error to be reported; for example, the current proposed design states:

In all cases, when encountering an error,
a message formatter MUST be able to signal an error or errors.

Therefore, that choice would also go against the above-mentioned experience-based programming guidelines. Is this not the case?

Just to be clear, I disagree about following this guideline for MF2, but here I'm trying to make sure that it's logically and consistently applied as it's being used as an argument in choosing between alternative designs.


### Require a best-effort message value and signaling of an error

> In all cases, when encountering an error,
> a message formatter MUST be able to signal an error or errors.
> It MUST also provide the appropriate fallback representation of the _message_ defined
> in this specification.

This alternative requires that an implementation provide both an error signal
and a means of accessing a "best-effort" fallback message.
This slightly relaxes the requirement of "returning" an error
(to allow a locally-appropriate signal of the error).

Under this alternative, implementations can be conformant by providing
two separate formatting methods or functions,
one of which returns the fallback string and one of which signals the error.

Similar to the current spec text,
this alternative requires implementations to provide useful information:
both a signal that an error occurred and a best effort message.
A downside to this alternative is that these requirements together assume that
all implementations will want to pay the cost of constructing a representative mesage
after the occurrence of an error.

### Allow implementations to determine all details

> When encountering an error during formatting,
Expand Down