Skip to content

Add name property to custom error classes #471

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

Merged
merged 1 commit into from
Dec 20, 2024

Conversation

rashfael
Copy link
Contributor

Adding the name property to custom errors would help us with serializing errors and re-throwing TerminalErrors through user-defined code sandboxes. Otherwise name on these custom errors is just Error.

@igalshilman
Copy link
Contributor

Hello @rashfael,
I didn't get exactly what is the issue that this PR solves? what are user-defined code sandboxes?
Does checking for instanceof / typeof doesn't cut it?

@rashfael
Copy link
Contributor Author

rashfael commented Dec 20, 2024

We're running user code and no-code runners as wasm components that can call apis on the host. For example if we throw a TerminalError inside our database update api the call stack looks like this:

  • Service / host
  • wasm guest
  • Host API

Every time we cross the boundary to wasm (so if the host calls wasm or wasm calls the api) we are serializing/deserializing the payload through json, including errors. If the host api throws an error, it needs to pass through the boundary twice.

When serializing we loose the js prototype chain and instanceof doesn't work anymore.
On the service side we re-instantiate TerminalErrors whenever we can so the restate sdk can check instanceof again.

Currently we try to serialize error.constructor.name, which is a bit hacky though (and minifiers are usually not preserving constructor names without being told).

Setting name would help us and be in line with built-in errors. (new TypeError()).name for example is TypeError.

@igalshilman
Copy link
Contributor

Understood, thanks for the explanation!

@igalshilman igalshilman merged commit 0eff045 into restatedev:main Dec 20, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants