MCPcopy Index your code
hub / github.com/nodejs/node / getErrorSourceLocation

Function getErrorSourceLocation

lib/internal/errors/error_source.js:26–59  ·  view source on GitHub ↗

* Get the source location of an error. If source map is enabled, resolve the source location * based on the source map. * * The `error.stack` must not have been accessed. The resolution is based on the structured * error stack data. * @param {Error|object} error An error object, or an object be

(error)

Source from the content-addressed store, hash-verified

24 * @returns {{sourceLine: string, startColumn: number}|undefined}
25 */
26function getErrorSourceLocation(error) {
27 const pos = getErrorSourcePositions(error);
28 const {
29 sourceLine,
30 scriptResourceName,
31 lineNumber,
32 startColumn,
33 } = pos;
34
35 // Source map is not enabled. Return the source line directly.
36 if (!getSourceMapsSupport().enabled) {
37 return { sourceLine, startColumn };
38 }
39
40 const sm = findSourceMap(scriptResourceName);
41 if (sm === undefined) {
42 return;
43 }
44 const {
45 originalLine,
46 originalColumn,
47 originalSource,
48 } = sm.findEntry(lineNumber - 1, startColumn);
49 const originalSourceLine = getSourceLine(sm, originalSource, originalLine, originalColumn);
50
51 if (!originalSourceLine) {
52 return;
53 }
54
55 return {
56 sourceLine: originalSourceLine,
57 startColumn: originalColumn,
58 };
59}
60
61const memberAccessTokens = [ '.', '?.', '[', ']' ];
62const memberNameTokens = [ 'name', 'string', 'num' ];

Callers 1

getErrorSourceExpressionFunction · 0.85

Calls 4

getSourceMapsSupportFunction · 0.85
findSourceMapFunction · 0.85
getSourceLineFunction · 0.85
findEntryMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…