Retrying async events results in FUNCTION_ERR

Hi, I’ve been playing around with async events and I’m testing the behavior of throw new InvocationError(...). However, I’m receiving a FUNCTION_ERR in my logs and the consumer isn’t called again.

Context: I’m using Forge with UI Kit 2. I have a small frontend modal which is calling a function. That function is pushing a message to the queue. A consumer function is processing this message. This connection working fine. It just stops working when I want to retry the message in my consumer.

This is what I do in my consumer function:

const resolver = new Resolver();
resolver.define("event-listener", async ({payload}) => {
  // processing payload... (skipped)

  // in case of error I throw the following:
  throw new InvocationError({
    retryAfter: 123,
    retryData: { ... },
    retryReason: InvocationErrorCode.FUNCTION_RETRY_REQUEST,

In the logs I can see the following log statements:

2024-02-29 14:53:07.680	{ "_retry":true, "retryOptions":{"retryAfter":123,"retryData":{},"retryReason":"FUNCTION_RETRY_REQUEST"}}
2024-02-29 14:53:07.698	{"message":"","name":"FUNCTION_ERR","stack":""}

Any idea why the FUNCTION_ERR appears? Is that intentional? If so, why is my consumer not called again? As far as I understand, using InvocationError is the expected way to retry a message, right?

Hey Sebastian,

I had the same problem as you earlier this week and here’s the solution. InvocationError is kinda (not really) a misnomer… If you inspect the type definitions, it’s a class that extends Response instead of Error as the name would suggest.

Therefore, for the retry mechanism to kick in you need to actually return a new instance of InvocationError like so:

try {
	// do something
} catch (e) {
    // retry
	return new InvocationError({})

The docs might need to be clearer regarding this.

1 Like

Oh damn… Yeah thanks for the helpful pointer! I totally missed the return statement in the docs… But the name InvocationError is really misleading :confused:

1 Like