Skip to content

Commit

Permalink
Consider async operation in runSync as a defect, add span based stack (
Browse files Browse the repository at this point in the history
  • Loading branch information
mikearnaldi authored Oct 2, 2024
1 parent cdead5c commit 83887ca
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-dolls-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

Consider async operation in runSync as a defect, add span based stack
2 changes: 1 addition & 1 deletion packages/effect/src/internal/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ export const originalInstance = <E>(obj: E): E => {
}

/* @internal */
const capture = <E>(obj: E & object, span: Option.Option<Tracer.Span>): E => {
export const capture = <E>(obj: E & object, span: Option.Option<Tracer.Span>): E => {
if (Option.isSome(span)) {
return new Proxy(obj, {
has(target, p) {
Expand Down
2 changes: 1 addition & 1 deletion packages/effect/src/internal/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export const unsafeRunSyncExit =
if (result) {
return result
}
throw asyncFiberException(fiberRuntime)
return core.exitDie(core.capture(asyncFiberException(fiberRuntime), core.currentSpanFromFiber(fiberRuntime)))
}

/** @internal */
Expand Down
10 changes: 10 additions & 0 deletions packages/effect/test/Effect/sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ const sum = (n: number): number => {
}

describe("Effect", () => {
it.it("runSyncExit with async is a defect with stack", () => {
const exit = Effect.runSyncExit(
Effect.promise(() => Promise.resolve(0)).pipe(Effect.withSpan("asyncSpan"))
)
if (Exit.isFailure(exit)) {
it.expect(Cause.pretty(exit.cause)).toContain("asyncSpan")
} else {
it.expect(exit._tag).toBe("Failure")
}
})
it.effect("sync - effect", () =>
Effect.gen(function*($) {
const sumEffect = (n: number): Effect.Effect<number, unknown> => {
Expand Down

0 comments on commit 83887ca

Please sign in to comment.