error-stack2
Advanced tools
Comparing version 1.0.9 to 1.0.10
@@ -7,2 +7,4 @@ 'use strict'; | ||
var ssplit = require('string-split-keep'); | ||
var errcode = require('err-code'); | ||
var util = require('util'); | ||
@@ -12,2 +14,3 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var ssplit__default = /*#__PURE__*/_interopDefaultLegacy(ssplit); | ||
var errcode__default = /*#__PURE__*/_interopDefaultLegacy(errcode); | ||
@@ -218,7 +221,15 @@ function trim(s) { | ||
function parseMessage(body) { | ||
const [, type, message] = body.match(REGEX_MATCH_MESSAGE); | ||
return { | ||
type, | ||
message | ||
}; | ||
try { | ||
const [, type, message] = body.match(REGEX_MATCH_MESSAGE); | ||
return { | ||
type, | ||
message | ||
}; | ||
} catch (e) { | ||
e.message = `Failed to parse body.\nreason: ${e.message}\nbody=${util.inspect(body)}`; | ||
errcode__default['default'](e, { | ||
body | ||
}); | ||
throw e; | ||
} | ||
} | ||
@@ -230,19 +241,27 @@ function parseStack(rawStack, detectMessage) { | ||
const { | ||
rawMessage, | ||
rawTrace | ||
} = parseBody(rawStack, detectMessage); | ||
const { | ||
type, | ||
message | ||
} = parseMessage(rawMessage); | ||
const traces = rawTrace.map(t => parseTrace(t, true)); | ||
return { | ||
type, | ||
message, | ||
traces, | ||
rawMessage, | ||
rawTrace, | ||
rawStack | ||
}; | ||
try { | ||
const { | ||
rawMessage, | ||
rawTrace | ||
} = parseBody(rawStack, detectMessage); | ||
const { | ||
type, | ||
message | ||
} = parseMessage(rawMessage); | ||
const traces = rawTrace.map(t => parseTrace(t, true)); | ||
return { | ||
type, | ||
message, | ||
traces, | ||
rawMessage, | ||
rawTrace, | ||
rawStack | ||
}; | ||
} catch (e) { | ||
errcode__default['default'](e, { | ||
rawStack, | ||
detectMessage | ||
}); | ||
throw e; | ||
} | ||
} | ||
@@ -249,0 +268,0 @@ function formatTrace({ |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("crlf-normalize");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=t(require("string-split-keep"));function n(e){return e.trim()}function a(e){return null==e}function l(e){return("number"==typeof e||"string"==typeof e)&&/^\d+$/.test(e.toString())}const o=/^([a-z][a-z0-9_]*):(?: ([\s\S]*))?$/i,s=/^at\s+/,i=/^eval\s+at\s+/,c=/^([ \t]*)(.+)$/;function u(e,t,r){if(!e.endsWith(r))return[e];let a,l=e.length-1,o=1;for(;--l>=0;){const n=e.charAt(l);if(n===r)o++;else if(n===t&&0==--o){a=l;break}}return[e.slice(0,a),e.slice(a+1,-1)].map(n)}function p(e){return!a(e)&&("object"==typeof e&&a(e.line)&&a(e.col)?null:l(e.line)&&l(e.col))}function f(e){const[t,n,a]=r.default(e,":",-3);return null!=a&&a.length&&null!=n&&n.length?{source:t,line:n,col:a}:{source:e}}function v(e){const{indent:t,rawLine:r}=d(e),[a,l]=r.replace(i,"").split(/,\s+/g).map(n),{eval:o,callee:s,calleeNote:c,...u}=x(a);return{evalCallee:s,evalCalleeNote:c,...u,evalTrace:f(l),indent:t}}function d(e){const[,t,r]=c.exec(e);return{indent:t,rawLine:r}}function x(e,t){const{indent:r,rawLine:n}=d(e),a=n.replace(s,"");let[l,o]=u(a,"(",")");o||([l,o]=[o,l]);const i={};if(l){const[e,t]=u(l,"[","]");i.callee=e,i.calleeNote=t}else i.callee=l;return"eval"===i.callee&&(i.eval=!0),!0!==t||n.startsWith("at")?(Object.assign(i,t&&g(o)?v(o):f(o)),!0!==t||m(i)?(i.indent=r,i):{raw:!0,indent:r,rawLine:n}):{raw:!0,indent:r,rawLine:n}}function g(e){return i.test(e)}function m(e){var t;return!k(e)&&(e.eval||l(e.line)||a(e.callee)&&(null===(t=e.source)||void 0===t?void 0:t.length)>0&&p(e))}function w(t,r){var l;let o,s;if(!a(r)){let{type:n}=y(t),a=S({type:n,message:r});if(0===t.indexOf(a)){let r=t.replace(a,""),n=e.R_CRLF.exec(r);0===(null==n?void 0:n.index)&&(o=e.lineSplit(n.input.replace(n[0],"")),s=a)}}if(null===(l=s)||void 0===l||!l.length){[s,...o]=e.lineSplit(t);const r=o.findIndex((e=>e.trimLeft().startsWith("at")&&m(x(n(e),!0))));s=[s,...o.splice(0,r)].join("\n")}return{rawMessage:s,rawTrace:o}}function y(e){const[,t,r]=e.match(o);return{type:t,message:r}}function $(e,t){if("string"!=typeof e)throw new TypeError("stack must be a string");const{rawMessage:r,rawTrace:n}=w(e,t),{type:a,message:l}=y(r);return{type:a,message:l,traces:n.map((e=>x(e,!0))),rawMessage:r,rawTrace:n,rawStack:e}}function h({callee:e,calleeNote:t,source:r,line:n,col:a}){const l=[r,n,a].filter((e=>void 0!==e)).join(":");return e?`${e}${t?` [${t}]`:""} (${l})`:l}function T({callee:e,evalTrace:t,evalCallee:r,evalCalleeNote:n,...a}){return`${e} (eval at ${h({...a,callee:null!=r?r:"<anonymous>",calleeNote:n})}, ${h(t)})`}function S({type:e,message:t}){return`${e}: ${null!=t?t:""}`}function L(e){var t;return`${null!==(t=e.indent)&&void 0!==t?t:" "}${e.rawLine}`}function k(e){return!0===e.raw}function b(e){return!0===e.eval}function j(e){var t;return k(e)?L(e):`${null!==(t=e.indent)&&void 0!==t?t:" "}at ${b(e)?T(e):h(e)}`}class E{constructor(e,t){Object.assign(this,$(e,t))}filter(e){return this.traces=this.traces.filter(e),this}format(){return M(this)}}function M(e){var t,r;const{type:n,message:a}=e,l=`${S({type:n,message:a})}`,o=(null!==(t=null===(r=e.traces)||void 0===r?void 0:r.map(j))&&void 0!==t?t:e.rawTrace).join("\n");return o?l+"\n"+o:l}function N(e,t){return new E(e,t)}exports.ErrorStack=E,exports._detectIndent=d,exports.breakBrackets=u,exports.default=N,exports.formatEvalTrace=T,exports.formatMessage=S,exports.formatRawLineTrace=L,exports.formatTrace=h,exports.formatTraceLine=j,exports.formatTraces=function(e){return null==e?void 0:e.map(j)},exports.isEvalSource=g,exports.isEvalTrace=b,exports.isRawLineTrace=k,exports.parseBody=w,exports.parseErrorStack=N,exports.parseEvalSource=v,exports.parseMessage=y,exports.parseSource=f,exports.parseStack=$,exports.parseTrace=x,exports.stringifyErrorStack=M,exports.validPosition=p,exports.validTrace=m; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("crlf-normalize"),t=require("string-split-keep"),r=require("err-code"),n=require("util");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=a(t),o=a(r);function l(e){return e.trim()}function i(e){return null==e}function c(e){return("number"==typeof e||"string"==typeof e)&&/^\d+$/.test(e.toString())}const u=/^([a-z][a-z0-9_]*):(?: ([\s\S]*))?$/i,p=/^at\s+/,f=/^eval\s+at\s+/,d=/^([ \t]*)(.+)$/;function v(e,t,r){if(!e.endsWith(r))return[e];let n,a=e.length-1,s=1;for(;--a>=0;){const o=e.charAt(a);if(o===r)s++;else if(o===t&&0==--s){n=a;break}}return[e.slice(0,n),e.slice(n+1,-1)].map(l)}function g(e){return!i(e)&&("object"==typeof e&&i(e.line)&&i(e.col)?null:c(e.line)&&c(e.col))}function x(e){const[t,r,n]=s.default(e,":",-3);return null!=n&&n.length&&null!=r&&r.length?{source:t,line:r,col:n}:{source:e}}function m(e){const{indent:t,rawLine:r}=w(e),[n,a]=r.replace(f,"").split(/,\s+/g).map(l),{eval:s,callee:o,calleeNote:i,...c}=y(n);return{evalCallee:o,evalCalleeNote:i,...c,evalTrace:x(a),indent:t}}function w(e){const[,t,r]=d.exec(e);return{indent:t,rawLine:r}}function y(e,t){const{indent:r,rawLine:n}=w(e),a=n.replace(p,"");let[s,o]=v(a,"(",")");o||([s,o]=[o,s]);const l={};if(s){const[e,t]=v(s,"[","]");l.callee=e,l.calleeNote=t}else l.callee=s;return"eval"===l.callee&&(l.eval=!0),!0!==t||n.startsWith("at")?(Object.assign(l,t&&h(o)?m(o):x(o)),!0!==t||$(l)?(l.indent=r,l):{raw:!0,indent:r,rawLine:n}):{raw:!0,indent:r,rawLine:n}}function h(e){return f.test(e)}function $(e){var t;return!M(e)&&(e.eval||c(e.line)||i(e.callee)&&(null===(t=e.source)||void 0===t?void 0:t.length)>0&&g(e))}function T(t,r){var n;let a,s;if(!i(r)){let{type:n}=S(t),o=j({type:n,message:r});if(0===t.indexOf(o)){let r=t.replace(o,""),n=e.R_CRLF.exec(r);0===(null==n?void 0:n.index)&&(a=e.lineSplit(n.input.replace(n[0],"")),s=o)}}if(null===(n=s)||void 0===n||!n.length){[s,...a]=e.lineSplit(t);const r=a.findIndex((e=>e.trimLeft().startsWith("at")&&$(y(l(e),!0))));s=[s,...a.splice(0,r)].join("\n")}return{rawMessage:s,rawTrace:a}}function S(e){try{const[,t,r]=e.match(u);return{type:t,message:r}}catch(t){throw t.message=`Failed to parse body.\nreason: ${t.message}\nbody=${n.inspect(e)}`,o.default(t,{body:e}),t}}function b(e,t){if("string"!=typeof e)throw new TypeError("stack must be a string");try{const{rawMessage:r,rawTrace:n}=T(e,t),{type:a,message:s}=S(r);return{type:a,message:s,traces:n.map((e=>y(e,!0))),rawMessage:r,rawTrace:n,rawStack:e}}catch(r){throw o.default(r,{rawStack:e,detectMessage:t}),r}}function k({callee:e,calleeNote:t,source:r,line:n,col:a}){const s=[r,n,a].filter((e=>void 0!==e)).join(":");return e?`${e}${t?` [${t}]`:""} (${s})`:s}function L({callee:e,evalTrace:t,evalCallee:r,evalCalleeNote:n,...a}){return`${e} (eval at ${k({...a,callee:null!=r?r:"<anonymous>",calleeNote:n})}, ${k(t)})`}function j({type:e,message:t}){return`${e}: ${null!=t?t:""}`}function E(e){var t;return`${null!==(t=e.indent)&&void 0!==t?t:" "}${e.rawLine}`}function M(e){return!0===e.raw}function N(e){return!0===e.eval}function C(e){var t;return M(e)?E(e):`${null!==(t=e.indent)&&void 0!==t?t:" "}at ${N(e)?L(e):k(e)}`}class _{constructor(e,t){Object.assign(this,b(e,t))}filter(e){return this.traces=this.traces.filter(e),this}format(){return q(this)}}function q(e){var t,r;const{type:n,message:a}=e,s=`${j({type:n,message:a})}`,o=(null!==(t=null===(r=e.traces)||void 0===r?void 0:r.map(C))&&void 0!==t?t:e.rawTrace).join("\n");return o?s+"\n"+o:s}function O(e,t){return new _(e,t)}exports.ErrorStack=_,exports._detectIndent=w,exports.breakBrackets=v,exports.default=O,exports.formatEvalTrace=L,exports.formatMessage=j,exports.formatRawLineTrace=E,exports.formatTrace=k,exports.formatTraceLine=C,exports.formatTraces=function(e){return null==e?void 0:e.map(C)},exports.isEvalSource=h,exports.isEvalTrace=N,exports.isRawLineTrace=M,exports.parseBody=T,exports.parseErrorStack=O,exports.parseEvalSource=m,exports.parseMessage=S,exports.parseSource=x,exports.parseStack=b,exports.parseTrace=y,exports.stringifyErrorStack=q,exports.validPosition=g,exports.validTrace=$; | ||
//# sourceMappingURL=error-stack2.cjs.production.min.js.map |
import { R_CRLF, lineSplit } from 'crlf-normalize'; | ||
import ssplit from 'string-split-keep'; | ||
import errcode from 'err-code'; | ||
import { inspect } from 'util'; | ||
@@ -208,7 +210,15 @@ function trim(s) { | ||
function parseMessage(body) { | ||
const [, type, message] = body.match(REGEX_MATCH_MESSAGE); | ||
return { | ||
type, | ||
message | ||
}; | ||
try { | ||
const [, type, message] = body.match(REGEX_MATCH_MESSAGE); | ||
return { | ||
type, | ||
message | ||
}; | ||
} catch (e) { | ||
e.message = `Failed to parse body.\nreason: ${e.message}\nbody=${inspect(body)}`; | ||
errcode(e, { | ||
body | ||
}); | ||
throw e; | ||
} | ||
} | ||
@@ -220,19 +230,27 @@ function parseStack(rawStack, detectMessage) { | ||
const { | ||
rawMessage, | ||
rawTrace | ||
} = parseBody(rawStack, detectMessage); | ||
const { | ||
type, | ||
message | ||
} = parseMessage(rawMessage); | ||
const traces = rawTrace.map(t => parseTrace(t, true)); | ||
return { | ||
type, | ||
message, | ||
traces, | ||
rawMessage, | ||
rawTrace, | ||
rawStack | ||
}; | ||
try { | ||
const { | ||
rawMessage, | ||
rawTrace | ||
} = parseBody(rawStack, detectMessage); | ||
const { | ||
type, | ||
message | ||
} = parseMessage(rawMessage); | ||
const traces = rawTrace.map(t => parseTrace(t, true)); | ||
return { | ||
type, | ||
message, | ||
traces, | ||
rawMessage, | ||
rawTrace, | ||
rawStack | ||
}; | ||
} catch (e) { | ||
errcode(e, { | ||
rawStack, | ||
detectMessage | ||
}); | ||
throw e; | ||
} | ||
} | ||
@@ -239,0 +257,0 @@ function formatTrace({ |
{ | ||
"name": "error-stack2", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "Parse and manipulate error.stack", | ||
@@ -55,2 +55,3 @@ "keywords": [ | ||
"crlf-normalize": "^1.0.6", | ||
"err-code": "^3.0.1", | ||
"string-split-keep": "^1.0.1", | ||
@@ -57,0 +58,0 @@ "ts-type": "^1.2.39", |
@@ -9,2 +9,4 @@ import { ITSPickExtra, ITSRequireAtLeastOne } from 'ts-type/lib/type/record'; | ||
import { isNumOnly } from './util/isNumOnly'; | ||
import errcode from 'err-code'; | ||
import { inspect } from 'util'; | ||
@@ -270,8 +272,21 @@ const AT = 'at' as const | ||
{ | ||
const [, type, message] = body.match(REGEX_MATCH_MESSAGE) | ||
try | ||
{ | ||
const [, type, message] = body.match(REGEX_MATCH_MESSAGE) | ||
return { | ||
type, | ||
message, | ||
return { | ||
type, | ||
message, | ||
} | ||
} | ||
catch (e: any) | ||
{ | ||
e.message = `Failed to parse body.\nreason: ${e.message}\nbody=${inspect(body)}`; | ||
errcode(e, { | ||
body, | ||
}); | ||
throw e | ||
} | ||
} | ||
@@ -286,18 +301,30 @@ | ||
const { rawMessage, rawTrace } = parseBody(rawStack, detectMessage); | ||
try | ||
{ | ||
const { rawMessage, rawTrace } = parseBody(rawStack, detectMessage); | ||
const { | ||
type, message, | ||
} = parseMessage(rawMessage) | ||
const { | ||
type, message, | ||
} = parseMessage(rawMessage) | ||
const traces = rawTrace.map(t => parseTrace(t, true)) | ||
const traces = rawTrace.map(t => parseTrace(t, true)) | ||
return { | ||
type, | ||
message, | ||
traces, | ||
rawMessage, | ||
rawTrace, | ||
rawStack, | ||
return { | ||
type, | ||
message, | ||
traces, | ||
rawMessage, | ||
rawTrace, | ||
rawStack, | ||
} | ||
} | ||
catch (e: any) | ||
{ | ||
errcode(e, { | ||
rawStack, | ||
detectMessage, | ||
}); | ||
throw e; | ||
} | ||
} | ||
@@ -304,0 +331,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
95740
1233
5
+ Addederr-code@^3.0.1
+ Addederr-code@3.0.1(transitive)