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