aboutsummaryrefslogtreecommitdiff
path: root/sql/win/lib/trace.js
diff options
context:
space:
mode:
authorStarscouts <starscouts@equestria.dev>2024-07-02 22:23:01 +0200
committerStarscouts <starscouts@equestria.dev>2024-07-02 22:23:01 +0200
commit04527db1831299fb3cba5c3127fd462939b448cf (patch)
treef4893e7b64faf9e23adf36f676fc6e30e745a784 /sql/win/lib/trace.js
parentce613801c07c90d3e886fd6002f6e8f833589632 (diff)
downloadfaunerie-3.1.0.tar.gz
faunerie-3.1.0.tar.bz2
faunerie-3.1.0.zip
Cancel Rust rewrite3.1.0
Diffstat (limited to 'sql/win/lib/trace.js')
-rwxr-xr-xsql/win/lib/trace.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/sql/win/lib/trace.js b/sql/win/lib/trace.js
new file mode 100755
index 0000000..1d84cb0
--- /dev/null
+++ b/sql/win/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;
+ });
+}