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

Add NonRetryableError #2634

Merged

Conversation

LuisDuarte1
Copy link
Contributor

No description provided.

export class NonRetryableError extends Error {
// `__brand` is needed for Workflows' engine to validate if the user returned a NonRetryableError
// this provides better DX because they can just extend NonRetryableError for their own Errors
public readonly __brand: string = 'NonRetryableError';
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking but...This is a bit unfortunate. I'd almost prefer something like NonRetryableError.isInstance(err) that can check an internal private... e.g.

const kTag = Symbol('kTag');

class NonRetryableError extends Error {
  [kTag] = kTag;  

  static isInstance(value) { return value[kTag] === kTag; }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is your suggested implementation serialized by RPC? If yes, I'm fine with replacing it 😅

Copy link
Member

Choose a reason for hiding this comment

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

ah, no, it would not be. Would you mind adding a comment then to indicate that the field is a public own property because it needs to be serialized for RPC?

Copy link
Member

Choose a reason for hiding this comment

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

Why don't we use name property as a way if distinguishing this error type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why don't we use name property as a way if distinguishing this error type?

It's done so that users can extend NonRetryableError (and override the name) for better observability and DX.

@sidharthachatterjee sidharthachatterjee merged commit 67d7678 into cloudflare:main Sep 3, 2024
10 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.

4 participants