Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: don't step on toes of internal stack-trace generation
  • Loading branch information
bcoe committed Oct 5, 2019
commit dd99ec7e9cd27bda148b6a8c382821ecd718b0f7
10 changes: 10 additions & 0 deletions lib/internal/source_map/source_map_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const cjsSourceMapCache = new WeakMap();
// on filenames.
const esmSourceMapCache = new Map();
const { fileURLToPath, URL } = require('url');
const { overrideStackTrace } = require('internal/errors');

let experimentalSourceMaps;
function maybeCacheSourceMap(filename, content, cjsModuleInstance) {
Expand Down Expand Up @@ -173,6 +174,15 @@ const prepareStackTrace = (globalThis, error, trace) => {
const { SourceMap } = require('internal/source_map/source_map');
const ErrorToString = Error.prototype.toString;
const errorString = ErrorToString.call(error);

// API for node internals to override error stack formatting
// without interfering with userland code.
if (overrideStackTrace.has(error)) {
const f = overrideStackTrace.get(error);
overrideStackTrace.delete(error);
return f(error, trace);
}

if (trace.length === 0) {
return errorString;
}
Expand Down