Innovenergy_trunk/frontend/node_modules/testcafe/lib/errors/stack-cleaning-hook.js

66 lines
7.6 KiB
JavaScript
Raw Normal View History

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const error_stack_parser_1 = __importDefault(require("error-stack-parser"));
const create_stack_filter_1 = __importDefault(require("./create-stack-filter"));
const ORIGINAL_STACK_TRACE_LIMIT = Error.stackTraceLimit;
const STACK_TRACE_LIMIT = 200;
const STACK_TRACE_LINE_RE = /^\s+at\s+.*$/;
exports.default = {
isEnabled: false,
_isStackTraceLine(stackLine) {
return STACK_TRACE_LINE_RE.test(stackLine);
},
_removeStackTraceLines(error) {
if (!error.stack) {
error.stack = '';
return;
}
const stackLines = error.stack.split('\n');
let stackLinesCount = 0;
while (stackLinesCount < stackLines.length && this._isStackTraceLine(stackLines[stackLines.length - 1 - stackLinesCount]))
stackLinesCount++;
error.stack = stackLines.slice(0, stackLines.length - stackLinesCount).join('\n');
if (stackLinesCount > 0)
error.stack += '\n';
},
_getFrames(error) {
try {
return error_stack_parser_1.default.parse(error);
}
catch (e) {
return [];
}
},
_renderFrameInfo(frames) {
return frames.map(frame => frame.getSource()).join('\n');
},
get enabled() {
return this.isEnabled;
},
set enabled(val) {
if (this.isEnabled === val)
return;
this.isEnabled = val;
// NOTE: Babel errors may have really deep stacks,
// so we increase stack trace capacity
if (this.isEnabled)
Error.stackTraceLimit = STACK_TRACE_LIMIT;
else
Error.stackTraceLimit = ORIGINAL_STACK_TRACE_LIMIT;
},
cleanError(error) {
let frames = this._getFrames(error);
if (!frames.length)
return error;
this._removeStackTraceLines(error);
const stackFilterFn = (0, create_stack_filter_1.default)(ORIGINAL_STACK_TRACE_LIMIT);
frames = frames.filter(stackFilterFn);
error.stack += this._renderFrameInfo(frames);
return error;
},
};
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3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