Skip to content

Throwing inside execute() produces unhandled errors #3002

Open
@punkpeye

Description

@punkpeye

Description

Something about the way execute is implemented is producing uncaught rejections.

I had to workaround with this:

let executionError: undefined | unknown;

const result = await redis.execute(async (client) => {
  try {
    const release = await mutex(client, scopedName);

    try {
      return await routine();
    } finally {
      log.info('releasing :scopedName', { scopedName });

      release();
    }
  } catch (error) {
    executionError = error;
  }
});

if (executionError) {
  throw executionError;
}

return result;

without this workaround, ie, just doing this:

const result = await redis.execute(async (client) => {
  const release = await mutex(client, scopedName);

  try {
    return await routine();
  } finally {
    log.info('releasing :scopedName', { scopedName });

    release();
  }
});

I am getting errors like:

Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error: First attempt fails
 ❯ routine app/services/redis.server.test.ts:209:19
    207|           name: 'error-lock',
    208|           routine: async () => {
    209|             throw new Error('First attempt fails');
       |                   ^
    210|           },
    211|         });
 ❯ app/services/redis.server.ts:55:20
 ❯ processTicksAndRejections node:internal/process/task_queues:105:5

This error originated in "app/services/redis.server.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running.
The latest test that might've caused the error is "releases lock even if routine throws". It might mean one of the following:
- The error was thrown, while Vitest was running this test.
- If the error occurred after the test had been completed, this was the last documented test before it was thrown.

Node.js Version

v24.1.0

Redis Server Version

8

Node Redis Version

5.5.6

Platform

macOS

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions