effect
effect copied to clipboard
From Discord: Unhandled error with `vitest` and `Effect.withSpan`
Summary
Summary
Several users are experiencing an issue with vitest and Effect.withSpan from the effect library. Specifically, when running a test that involves Effect.withSpan and an Error object, an unhandled error occurs. This issue does not appear when the error is a string or when Effect.withSpan is not used.
Key Takeaways
-
Issue Description:
- When running a test with
Effect.withSpanand anErrorobject, an unhandled error occurs. - The issue does not occur when the error is a string or when
Effect.withSpanis not used.
- When running a test with
-
Workaround:
- Catching the error using
.catch(e => { console.log(e) })prevents the unhandled error.
- Catching the error using
-
Version Specific:
- The issue does not occur in
vitestversion 1.5.3 but is present in version 1.6.0.
- The issue does not occur in
-
Potential Cause:
- The problem seems to be related to the handling of
file://URLs in stack traces. Specifically, the absence offile://in certain parts of the stack trace causes the issue.
- The problem seems to be related to the handling of
-
Code Insight:
- The line
this[FiberFailureCauseId] = causeinFiberFailureImplmight be causing the issue. - Removing this line or modifying it to include
cause: this[FiberFailureCauseId].toJSON()can serve as a temporary fix.
- The line
Conclusion
The issue appears to be related to how vitest handles stack traces and file:// URLs in its newer version (1.6.0). Users experiencing this issue can either downgrade to version 1.5.3 or apply the suggested code modifications as a temporary workaround.
Discord thread
https://discord.com/channels/795981131316985866/1242486270547067012