Throwing NonRetryableErrors

So I currently have an activity that throws a non retryable error, but based on the behavior of my workflow, it seems like I’m not doing so correctly, specifically, it keeps retrying doSomething(), and never gets to handleFailure.

const activities =  proxyActivities<testActivities>({
  startToCloseTimeout: '1h',
  heartbeatTimeout: '10m',
  taskQueue: 'default',
  retry: {
    nonRetryableErrorTypes: ['do_not_retry'],
  },
});

export const workflow = async () => {
    try {
        await activities.doSomething();
    } catch (e) {
        await activities.handleFailure(e);
    }
}

and then my activities are defined as

const testActivities {
    async doSomething() {
         throw new Error('do_not_retry');
    }
    async handleFailure(err) {
        console.log(err);
    }
}
1 Like

nonRetryableErrorTypes takes a list of ApplicationFailure types. Replace

throw new Error('do_not_retry');

with

throw new ApplicationFailure('message', 'do_not_retry')

(type is second param)

Appreciate it. Something small btw, in the docs you referenced, it seems like create and fromError don’t work anymore (I couldn’t find the static modules in my installed temporal package) but are referenced in the docs? Also just to double check, but using/throwing Applicationfailure.nonRetryable will ensure that the activity isn’t retried, without me having to specify it in the proxyActivities retry config?

1 Like

Sorry, it’s showing latest main—create and fromError will be in the next release.

using/throwing Applicationfailure.nonRetryable will ensure that the activity isn’t retried, without me having to specify it in the proxyActivities retry config?

Yes

1 Like