Skip to content
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

feat: allow errors to propagate extra information upstream #296

Open
tmedwards opened this issue Apr 19, 2024 · 0 comments
Open

feat: allow errors to propagate extra information upstream #296

tmedwards opened this issue Apr 19, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@tmedwards
Copy link
Owner

tmedwards commented Apr 19, 2024

Allow errors (read: exceptions, Error instances) to propagate extra information with them upstream to their eventual endpoint.

Rational

When an error occurs it is sometimes possible to analyze the situation so that extra details about the error, which could be helpful to either the end user or players, may be generated. These extra details are not always suitable for inclusion directly within the error message—e.g., a suggested course of action.

Therefore, it is desirable to have a mechanism by which these extra details may be included with the error as it travels upstream towards its eventual endpoint. Said mechanism is similar to using the <Error>.cause property to provide structured data and could be used to implement this feature.

Suggestion

When extra details can be generated, assign a specifically constructed "details" object to <Error>.cause.

A possible example of the format of the "details" object:

  • code: Number or string ID representing the issue.
  • hint: Suggested resolution.
  • origin: Original exception, if any.
  • values: Data about the error—probably an array. Possibly closely tied to code, so the endpoint knows what to do with the data.

Potential issues

The <Error>.cause property debuted in most browsers in the latter half of 2021, so Error instances in older browser aren't going have it. This means that it will need to be added to Error instances in affected browsers. Adding expando properties to JavaScript natives is generally frowned upon, however, it has been, and occasionally still is, done for various reasons, some good, and presents no real danger in this instance. This is not a blocker.

@tmedwards tmedwards added the enhancement New feature or request label Apr 19, 2024
@tmedwards tmedwards self-assigned this Apr 19, 2024
tmedwards added a commit that referenced this issue Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant