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

Function getLocationsFromFrames

ark/fs/getCurrentLine.ts:89–118  ·  view source on GitHub ↗
(frames: string[])

Source from the content-addressed store, hash-verified

87 * Get the locations from a list of error stack frames.
88 */
89const getLocationsFromFrames = (frames: string[]): Location[] => {
90 // Prepare
91 const locations: Location[] = []
92
93 // Cycle through the lines
94 for (const frame of frames) {
95 // ensure each line is a string
96 const line = (frame || "").toString()
97
98 // skip empty lines
99 if (line.length === 0) continue
100
101 // Error
102 // at file:///Users/balupton/Projects/active/get-current-line/asd.js:1:13
103 // at ModuleJob.run (internal/modules/esm/module_job.js:140:23)
104 // at async Loader.import (internal/modules/esm/loader.js:165:24)
105 // at async Object.loadESM (internal/process/esm_loader.js:68:5)
106 const match = line.match(lineRegex)
107 if (match && match.groups) {
108 locations.push({
109 method: match.groups.method || "",
110 file: match.groups.file || "",
111 line: Number(match.groups.line),
112 char: Number(match.groups.char)
113 })
114 }
115 }
116
117 return locations
118}
119
120/**
121 * If a location is not found, this is the result that is used.

Callers 1

getLocationsFromErrorFunction · 0.85

Calls 3

matchMethod · 0.80
toStringMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected