Skip to main content

Class: ApplicationFailure

common.ApplicationFailure

ApplicationFailures are used to communicate application-specific failures in Workflows and Activities.

The type property is matched against RetryPolicy.nonRetryableErrorTypes to determine if an instance of this error is retryable. Another way to avoid retrying is by setting the nonRetryable flag to true.

In Workflows, if you throw a non-ApplicationFailure, the Workflow Task will fail and be retried. If you throw an ApplicationFailure, the Workflow Execution will fail.

In Activities, you can either throw an ApplicationFailure or another Error to fail the Activity Task. In the latter case, the Error will be converted to an ApplicationFailure. The conversion is done as following:

  • type is set to error.constructor?.name ?? error.name
  • message is set to error.message
  • nonRetryable is set to false
  • details are set to null
  • stack trace is copied from the original error

When an Activity Execution fails, the ApplicationFailure from the last Activity Task will be the cause of the ActivityFailure thrown in the Workflow.

Hierarchy

Constructors

constructor

new ApplicationFailure(message?, type?, nonRetryable?, details?, cause?, nextRetryDelay?): ApplicationFailure

Alternatively, use fromError or create.

Parameters

NameType
message?null | string
type?null | string
nonRetryable?null | boolean
details?null | unknown[]
cause?Error
nextRetryDelay?null | Duration

Returns

ApplicationFailure

Overrides

TemporalFailure.constructor

Properties

cause

Optional Readonly cause: Error

Inherited from

TemporalFailure.cause


details

Optional Readonly details: null | unknown[]


failure

Optional failure: IFailure

The original failure that constructed this error.

Only present if this error was generated from an external operation.

Inherited from

TemporalFailure.failure


message

message: string

Inherited from

TemporalFailure.message


name

name: string

Inherited from

TemporalFailure.name


nextRetryDelay

Optional Readonly nextRetryDelay: null | Duration


nonRetryable

Optional Readonly nonRetryable: null | boolean


stack

Optional stack: string

Inherited from

TemporalFailure.stack


type

Optional Readonly type: null | string


prepareStackTrace

Static Optional prepareStackTrace: (err: Error, stackTraces: CallSite[]) => any

Optional override for formatting stack traces

See

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

Type declaration

▸ (err, stackTraces): any

Optional override for formatting stack traces

Parameters
NameType
errError
stackTracesCallSite[]
Returns

any

See

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

Inherited from

TemporalFailure.prepareStackTrace


stackTraceLimit

Static stackTraceLimit: number

Inherited from

TemporalFailure.stackTraceLimit

Methods

captureStackTrace

captureStackTrace(targetObject, constructorOpt?): void

Create .stack property on a target object

Parameters

NameType
targetObjectobject
constructorOpt?Function

Returns

void

Inherited from

TemporalFailure.captureStackTrace


create

create(options): ApplicationFailure

Create a new ApplicationFailure.

By default, will be retryable (unless its type is included in RetryPolicy.nonRetryableErrorTypes).

Parameters

NameType
optionsApplicationFailureOptions

Returns

ApplicationFailure


fromError

fromError(error, overrides?): ApplicationFailure

Create a new ApplicationFailure from an Error object.

First calls ensureApplicationFailure(error) and then overrides any fields provided in overrides.

Parameters

NameType
errorunknown
overrides?ApplicationFailureOptions

Returns

ApplicationFailure


nonRetryable

nonRetryable(message?, type?, ...details): ApplicationFailure

Get a new ApplicationFailure with the nonRetryable flag set to true.

When thrown from an Activity or Workflow, the Activity or Workflow will not be retried (even if type is not listed in RetryPolicy.nonRetryableErrorTypes).

Parameters

NameTypeDescription
message?null | stringOptional error message
type?null | stringOptional error type
...detailsunknown[]Optional details about the failure. Serialized by the Worker's PayloadConverter.

Returns

ApplicationFailure


retryable

retryable(message?, type?, ...details): ApplicationFailure

Get a new ApplicationFailure with the nonRetryable flag set to false. Note that this error will still not be retried if its type is included in RetryPolicy.nonRetryableErrorTypes.

Parameters

NameTypeDescription
message?null | stringOptional error message
type?null | stringOptional error type (used by RetryPolicy.nonRetryableErrorTypes)
...detailsunknown[]Optional details about the failure. Serialized by the Worker's PayloadConverter.

Returns

ApplicationFailure