cloudflare / cloudflare/workers-sdk

🐛 BUG: Vitest Integration failure with error thrown from Durable Object RPC

Open
#7,707 2 comments 9 reactions 0 assignees View on GitHub
package:vitest
Dominant language
TypeScript
Stars
4.5k
Forks
1.5k
Avg merge
3d 8h
Merged PRs (30d)
186

Description

### Which Cloudflare product(s) does this pertain to?

Wrangler, Workers Vitest Integration

### What versions are you using?

3.100.0 [Wrangler], 20.11.1 [Node]

### What operating system and version are you using?

Mac 15.1.1

### Please provide a link to a minimal reproduction

https://github.com/its-jman/rpc-error-repro

### Describe the Bug

With a durable object, and vitest integration as simple as:
```
export class MyDurable extends DurableObject {
async myCustomFunc() { throw new Error("My impl is broken") }
}
```

And running tests through the vitest integration:
```
it('fetches feed', async () => {
const stub = env.MY_DURABLE.get(env.MY_DURABLE.idFromName('main'))
const res = await expect(() => stub.myCustomFunc()).rejects.toThrowError()
})
```

I end up with `Vitest caught 1 unhandled error during the test run., and Failed to pop isolated storage stack frame`

I'd expect this to be propagated up through rpc as it is mentioned in the docs [here](https://developers.cloudflare.com/workers/runtime-apis/rpc/error-handling/) so Vitest can handle it.

Why doesn't this error propagate to get handled by Vitest? What is the suggested way to handle thrown errors in implementation in tests?

### Please provide any relevant error logs

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.