MCPcopy Create free account
hub / github.com/arktypeio/arktype / getFramesFromError

Function getFramesFromError

ark/fs/getCurrentLine.ts:54–81  ·  view source on GitHub ↗
(error: Error)

Source from the content-addressed store, hash-verified

52 * For an error instance, return its stack frames as an array.
53 */
54export const getFramesFromError = (error: Error): string[] => {
55 // Create an error
56 let stack: Error["stack"] | null, frames: any[]
57
58 // And attempt to retrieve it's stack
59 // https://github.com/winstonjs/winston/issues/401#issuecomment-61913086
60 try {
61 stack = error.stack
62 // eslint-disable-next-line @typescript-eslint/no-unused-vars
63 } catch (error1) {
64 try {
65 // @ts-expect-error https://github.com/winstonjs/winston/issues/401#issuecomment-61913086
66 const previous = err.__previous__ || err.__previous
67 stack = previous && previous.stack
68 // eslint-disable-next-line @typescript-eslint/no-unused-vars
69 } catch (error2) {
70 stack = null
71 }
72 }
73
74 // Handle different stack formats
75 if (stack)
76 frames = Array.isArray(stack) ? Array(stack) : stack.toString().split("\n")
77 else frames = []
78
79 // Parse our frames
80 return frames
81}
82
83const lineRegex =
84 /\s+at\s(?:(?<method>.+?)\s\()?(?<file>.+?):(?<line>\d+):(?<char>\d+)\)?\s*$/

Callers 2

getCallStackFunction · 0.90
getLocationsFromErrorFunction · 0.85

Calls 2

ArrayInterface · 0.85
toStringMethod · 0.65

Tested by

no test coverage detected