UNPKG

@sentry/core

Version:
91 lines (90 loc) • 3.13 kB
import { normalizeStackTracePath } from "./stacktrace.js"; // src/utils/node-stack-trace.ts /** * Does this filename look like it's part of the app code? */ function filenameIsInApp(filename, isNative = false) { return !(isNative || filename && !filename.startsWith("/") && !filename.match(/^[A-Z]:/) && !filename.startsWith(".") && !filename.match(/^[a-zA-Z]([a-zA-Z0-9.\-+])*:\/\//)) && filename !== void 0 && !filename.includes("node_modules/"); } /** Node Stack line parser */ function node(getModule) { const FILENAME_MATCH = /^\s*[-]{4,}$/; const FULL_MATCH = /at (?:async )?(?:(?=.*\)\s*$)(.+?)\s+\()?(?:(.+):(\d+):(\d+)?|([^)]+))\)?/; const DATA_URI_MATCH = /at (?:async )?(.+?) \(data:(.*?),/; return (line) => { const dataUriMatch = line.match(DATA_URI_MATCH); if (dataUriMatch) return { filename: `<data:${dataUriMatch[2]}>`, function: dataUriMatch[1] }; const lineMatch = line.match(FULL_MATCH); if (lineMatch) { let object; let method; let functionName; let typeName; let methodName; if (lineMatch[1]) { functionName = lineMatch[1]; let methodStart = functionName.lastIndexOf("."); if (functionName[methodStart - 1] === ".") methodStart--; if (methodStart > 0) { object = functionName.slice(0, methodStart); method = functionName.slice(methodStart + 1); const objectEnd = object.indexOf(".Module"); if (objectEnd > 0) { functionName = functionName.slice(objectEnd + 1); object = object.slice(0, objectEnd); } } typeName = void 0; } if (method) { typeName = object; methodName = method; } if (method === "<anonymous>") { methodName = void 0; functionName = void 0; } if (functionName === void 0) { methodName = methodName || "?"; functionName = typeName ? `${typeName}.${methodName}` : methodName; } let filename = normalizeStackTracePath(lineMatch[2]); const isNative = lineMatch[5] === "native"; if (!filename && lineMatch[5] && !isNative) filename = lineMatch[5]; const maybeDecodedFilename = filename ? _safeDecodeURI(filename) : void 0; return { filename: maybeDecodedFilename ?? filename, module: maybeDecodedFilename && getModule?.(maybeDecodedFilename), function: functionName, lineno: _parseIntOrUndefined(lineMatch[3]), colno: _parseIntOrUndefined(lineMatch[4]), in_app: filenameIsInApp(filename || "", isNative) }; } if (line.match(FILENAME_MATCH)) return { filename: line }; }; } /** * Node.js stack line parser * * This is in @sentry/core so it can be used from the Electron SDK in the browser for when `nodeIntegration == true`. * This allows it to be used without referencing or importing any node specific code which causes bundlers to complain */ function nodeStackLineParser(getModule) { return [90, node(getModule)]; } function _parseIntOrUndefined(input) { return parseInt(input || "", 10) || void 0; } function _safeDecodeURI(filename) { try { return decodeURI(filename); } catch { return; } } export { filenameIsInApp, node, nodeStackLineParser }; //# sourceMappingURL=node-stack-trace.js.map