-
Notifications
You must be signed in to change notification settings - Fork 211
fix(common): preserve Error.cause in activity failures #2292
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import test from 'ava'; | ||
| import { defaultFailureConverter } from '../converter/data-converter'; | ||
| import { defaultPayloadConverter } from '../converter/payload-converter'; | ||
| import { ensureApplicationFailure } from '../failure'; | ||
|
|
||
| test('preserves Error.cause when converting an application failure', (t) => { | ||
| const cause = new Error('connection terminated'); | ||
| const error = new Error('query failed', { cause }); | ||
|
|
||
| const applicationFailure = ensureApplicationFailure(error); | ||
| const failure = defaultFailureConverter.errorToFailure(applicationFailure, defaultPayloadConverter); | ||
|
|
||
| t.is(applicationFailure.cause, cause); | ||
| t.is(failure.cause?.message, cause.message); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -427,6 +427,7 @@ export class WorkflowExecutionAlreadyStartedError extends TemporalFailure { | |
| * - `message`: `error.message` or `String(error)` | ||
| * - `type`: `error.constructor.name` or `error.name` | ||
| * - `stack`: `error.stack` or `''` | ||
| * - `cause`: `error.cause` when it is an `Error` | ||
| */ | ||
| export function ensureApplicationFailure(error: unknown): ApplicationFailure { | ||
| if (error instanceof ApplicationFailure) { | ||
|
|
@@ -435,7 +436,8 @@ export function ensureApplicationFailure(error: unknown): ApplicationFailure { | |
|
|
||
| const message = (isRecord(error) && String(error.message)) || String(error); | ||
| const type = (isRecord(error) && (error.constructor?.name ?? error.name)) || undefined; | ||
| const failure = ApplicationFailure.create({ message, type, nonRetryable: false }); | ||
| const cause = isRecord(error) && error.cause instanceof Error ? error.cause : undefined; | ||
| const failure = ApplicationFailure.create({ message, type, nonRetryable: false, cause }); | ||
|
Comment on lines
+439
to
+440
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When an Activity throws an Useful? React with 👍 / 👎. |
||
| failure.stack = (isRecord(error) && String(error.stack)) || ''; | ||
| return failure; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.