error-stack2
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -75,3 +75,3 @@ import { ITSPartialRecord, ITSPickExtra, ITSRequireAtLeastOne } from 'ts-type/lib/type/record'; | ||
}; | ||
export declare function parseMessage(body: string): IParsedWithoutTrace; | ||
export declare function parseMessage(body: string, looseMode?: boolean): IParsedWithoutTrace; | ||
export declare function parseStack(rawStack: string, detectMessage?: string): IParsed; | ||
@@ -78,0 +78,0 @@ export declare function formatTrace({ callee, calleeNote, source, line, col, }: ITSPickExtra<ITrace, "source">): string; |
{ | ||
"name": "error-stack2", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Parse and manipulate error.stack", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -19,2 +19,4 @@ import { ITSPickExtra, ITSRequireAtLeastOne } from 'ts-type/lib/type/record'; | ||
const REGEX_MATCH_MESSAGE_LOOSE = new RegExp(REGEX_MATCH_MESSAGE.source, REGEX_MATCH_MESSAGE.flags + 'm'); | ||
const REGEX_REMOVE_AT = /^at\s+/ | ||
@@ -229,7 +231,7 @@ const REGEX_STARTS_WITH_EVAL_AT = /^eval\s+at\s+/ | ||
{ | ||
let { type } = parseMessage(rawStack); | ||
let { type, message } = parseMessage(rawStack, true); | ||
let mf = formatMessage({ | ||
type, | ||
message: detectMessage, | ||
message: detectMessage === '' ? message : detectMessage, | ||
}); | ||
@@ -258,3 +260,4 @@ | ||
// A error message might have multiple lines | ||
const index = rawTrace.findIndex(line => line.trimLeft().startsWith(AT) && validTrace(parseTrace(trim(line), true))); | ||
const index = rawTrace.findIndex(line => line.trimLeft() | ||
.startsWith(AT) && validTrace(parseTrace(trim(line), true))); | ||
@@ -270,7 +273,7 @@ rawMessage = [rawMessage, ...rawTrace.splice(0, index)].join(LF) | ||
export function parseMessage(body: string): IParsedWithoutTrace | ||
export function parseMessage(body: string, looseMode?: boolean): IParsedWithoutTrace | ||
{ | ||
try | ||
{ | ||
const [, type, code, message] = body.match(REGEX_MATCH_MESSAGE) | ||
const [, type, code, message] = body.match(looseMode ? REGEX_MATCH_MESSAGE_LOOSE : REGEX_MATCH_MESSAGE); | ||
@@ -299,3 +302,6 @@ return { | ||
{ | ||
throw new TypeError('stack must be a string') | ||
throw errcode(new TypeError('stack must be a string'), { | ||
rawStack, | ||
detectMessage, | ||
}); | ||
} | ||
@@ -302,0 +308,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
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
102340
1279