Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add NonRetryableError #2634

Merged

Conversation

LuisDuarte1
Copy link
Collaborator

No description provided.

@LuisDuarte1 LuisDuarte1 requested review from a team as code owners August 30, 2024 16:25
@LuisDuarte1 LuisDuarte1 requested review from fhanau and mar-cf August 30, 2024 16:25
@LuisDuarte1 LuisDuarte1 force-pushed the lduarte/non-retryable-error branch from 3fe32c6 to 3da1b5e Compare August 30, 2024 16:46
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
Collaborator 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
Collaborator 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.

@LuisDuarte1 LuisDuarte1 force-pushed the lduarte/non-retryable-error branch from 3da1b5e to da18180 Compare September 2, 2024 08:53
@sidharthachatterjee sidharthachatterjee merged commit 67d7678 into cloudflare:main Sep 3, 2024
10 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants