Skip to content

Commit

Permalink
ensure multiline error messages are preserved in cause rendering (#2981)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored Jun 12, 2024
1 parent 7f987a3 commit 3572646
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/long-tools-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

ensure multiline error messages are preserved in cause rendering
2 changes: 1 addition & 1 deletion packages/effect/src/internal/cause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ export const spanToTrace = globalValue("effect/Tracer/spanToTrace", () => new We

const prettyErrorStack = (message: string, stack: string, span?: Span | undefined): string => {
const out: Array<string> = [message]
const lines = stack.split("\n")
const lines = stack.startsWith(message) ? stack.slice(message.length).split("\n") : stack.split("\n")

for (let i = 1; i < lines.length; i++) {
if (lines[i].includes("Generator.next")) {
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 @@ -141,4 +141,17 @@ describe("Effect", () => {
yield* Effect.void
it.expect({ foo: "ok" }).toStrictEqual({ foo: "bar" })
}))

it.effect("multiline message", () =>
Effect.gen(function*() {
const cause = yield* Effect.fail(new Error("Multi-line\nerror\nmessage")).pipe(
Effect.sandbox,
Effect.flip
)
const pretty = Cause.pretty(cause)
assert.isTrue(pretty.startsWith(`Error: Multi-line
error
message
at`))
}))
})

0 comments on commit 3572646

Please sign in to comment.