MCPcopy Create free account
hub / github.com/Effect-TS/effect / prettyErrorStack

Function prettyErrorStack

packages/effect/src/internal/cause.ts:981–1032  ·  view source on GitHub ↗
(message: string, stack: string, span?: Span | undefined)

Source from the content-addressed store, hash-verified

979export const spanToTrace = globalValue("effect/Tracer/spanToTrace", () => new WeakMap())
980
981const prettyErrorStack = (message: string, stack: string, span?: Span | undefined): string => {
982 const out: Array<string> = [message]
983 const lines = stack.startsWith(message) ? stack.slice(message.length).split("\n") : stack.split("\n")
984
985 for (let i = 1; i < lines.length; i++) {
986 if (lines[i].includes(" at new BaseEffectError") || lines[i].includes(" at new YieldableError")) {
987 i++
988 continue
989 }
990 if (lines[i].includes("Generator.next")) {
991 break
992 }
993 if (lines[i].includes("effect_internal_function")) {
994 break
995 }
996 out.push(
997 lines[i]
998 .replace(/at .*effect_instruction_i.*\((.*)\)/, "at $1")
999 .replace(/EffectPrimitive\.\w+/, "<anonymous>")
1000 )
1001 }
1002
1003 if (span) {
1004 let current: Span | AnySpan | undefined = span
1005 let i = 0
1006 while (current && current._tag === "Span" && i < 10) {
1007 const stackFn = spanToTrace.get(current)
1008 if (typeof stackFn === "function") {
1009 const stack = stackFn()
1010 if (typeof stack === "string") {
1011 const locationMatchAll = stack.matchAll(locationRegex)
1012 let match = false
1013 for (const [, location] of locationMatchAll) {
1014 match = true
1015 out.push(` at ${current.name} (${location})`)
1016 }
1017 if (!match) {
1018 out.push(` at ${current.name} (${stack.replace(/^at /, "")})`)
1019 }
1020 } else {
1021 out.push(` at ${current.name}`)
1022 }
1023 } else {
1024 out.push(` at ${current.name}`)
1025 }
1026 current = Option.getOrUndefined(current.parent)
1027 i++
1028 }
1029 }
1030
1031 return out.join("\n")
1032}
1033
1034/** @internal */
1035export const spanSymbol = Symbol.for("effect/SpanAnnotation")

Callers 1

makePrettyErrorFunction · 0.85

Calls 3

splitMethod · 0.80
getMethod · 0.65
joinMethod · 0.65

Tested by

no test coverage detected