Skip to content

Commit

Permalink
render nested causes in Cause.pretty (#3246)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored Jul 13, 2024
1 parent 42aec0e commit eb1c4d4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/witty-snails-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

render nested causes in Cause.pretty
3 changes: 3 additions & 0 deletions packages/effect/src/internal/cause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,9 @@ const renderErrorCause = (cause: PrettyError, prefix: string) => {
for (let i = 1, len = lines.length; i < len; i++) {
stack += `\n${prefix}${lines[i]}`
}
if (cause.cause) {
stack += ` {\n${renderErrorCause(cause.cause as PrettyError, `${prefix} `)}\n${prefix}}`
}
return stack
}

Expand Down
13 changes: 13 additions & 0 deletions packages/effect/test/Effect/cause-rendering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,17 @@ message
const pretty = Cause.pretty(cause, { renderErrorCause: true })
assert.include(pretty, "[cause]: Error: child")
}))

it.effect("pretty nested cause", () =>
Effect.gen(function*() {
const cause = yield* Effect.fail(
new Error("parent", { cause: new Error("child", { cause: new Error("child2") }) })
).pipe(
Effect.sandbox,
Effect.flip
)
const pretty = Cause.pretty(cause, { renderErrorCause: true })
assert.include(pretty, "[cause]: Error: child")
assert.include(pretty, "[cause]: Error: child2")
}))
})

0 comments on commit eb1c4d4

Please sign in to comment.