Skip to content

Commit

Permalink
fix: make NonRetryableError non-abstract in types
Browse files Browse the repository at this point in the history
Basically, we won't get NonRetryableError serialization done properly
because we would have to implement our own Error Serializer for this
which might not be worth it, at least for launch. Even if we fix this
later, it's okay to let users throw a raw NonRetryableError anyway.
  • Loading branch information
LuisDuarte1 committed Oct 16, 2024
1 parent 0166594 commit bfb7fce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
7 changes: 0 additions & 7 deletions src/cloudflare/internal/workflows-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
// https://opensource.org/licenses/Apache-2.0

export class NonRetryableError extends Error {
// `__brand` is how engine validates that the user returned a `NonRetryableError`
// imported from "cloudflare:workflows"
// This enables them to extend NonRetryableError for their own Errors
// as well by overriding name
// Private fields are not serialized over RPC
public readonly __brand: string = 'NonRetryableError';

public constructor(message: string, name = 'NonRetryableError') {
super(message);
this.name = name;
Expand Down
14 changes: 5 additions & 9 deletions types/defines/workflows.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
/**
* NonRetryableError allows for a user to throw a fatal error
* that makes a Workflow instance fail immediately without triggering a retry
*/
declare module "cloudflare:workflows" {
export abstract class NonRetryableError extends Error {
/**
* `__brand` is used to differentiate between `NonRetryableError` and `Error`
* and is omitted from the constructor because users should not set it
*/
/**
* NonRetryableError allows for a user to throw a fatal error
* that makes a Workflow instance fail immediately without triggering a retry
*/
export class NonRetryableError extends Error {
public constructor(message: string, name?: string);
}
}
Expand Down

0 comments on commit bfb7fce

Please sign in to comment.