diff options
author | RaindropsSys <raindrops@equestria.dev> | 2024-06-13 15:46:03 +0200 |
---|---|---|
committer | RaindropsSys <raindrops@equestria.dev> | 2024-06-13 15:46:03 +0200 |
commit | e44e2fe070484e06d384a31ef2699c3a2d5d474e (patch) | |
tree | 2d5eb5d1b01646270d18cf1f2d94519966d6e7de /updater/sql/mac/lib/trace.js | |
download | faunerie-e44e2fe070484e06d384a31ef2699c3a2d5d474e.tar.gz faunerie-e44e2fe070484e06d384a31ef2699c3a2d5d474e.tar.bz2 faunerie-e44e2fe070484e06d384a31ef2699c3a2d5d474e.zip |
GitHub migration
Diffstat (limited to 'updater/sql/mac/lib/trace.js')
-rwxr-xr-x | updater/sql/mac/lib/trace.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/updater/sql/mac/lib/trace.js b/updater/sql/mac/lib/trace.js new file mode 100755 index 0000000..1d84cb0 --- /dev/null +++ b/updater/sql/mac/lib/trace.js @@ -0,0 +1,38 @@ +// Inspired by https://github.com/tlrobinson/long-stack-traces +const util = require('util'); + +function extendTrace(object, property, pos) { + const old = object[property]; + object[property] = function() { + const error = new Error(); + const name = object.constructor.name + '#' + property + '(' + + Array.prototype.slice.call(arguments).map(function(el) { + return util.inspect(el, false, 0); + }).join(', ') + ')'; + + if (typeof pos === 'undefined') pos = -1; + if (pos < 0) pos += arguments.length; + const cb = arguments[pos]; + if (typeof arguments[pos] === 'function') { + arguments[pos] = function replacement() { + const err = arguments[0]; + if (err && err.stack && !err.__augmented) { + err.stack = filter(err).join('\n'); + err.stack += '\n--> in ' + name; + err.stack += '\n' + filter(error).slice(1).join('\n'); + err.__augmented = true; + } + return cb.apply(this, arguments); + }; + } + return old.apply(this, arguments); + }; +} +exports.extendTrace = extendTrace; + + +function filter(error) { + return error.stack.split('\n').filter(function(line) { + return line.indexOf(__filename) < 0; + }); +} |