diff --git a/lib/internal/assert/utils.js b/lib/internal/assert/utils.js index 59b5a16f13..d059fa89ba 100644 --- a/lib/internal/assert/utils.js +++ b/lib/internal/assert/utils.js @@ -9,7 +9,6 @@ const { SafeMap, StringPrototypeCharCodeAt, StringPrototypeIncludes, - StringPrototypeIndexOf, StringPrototypeReplace, StringPrototypeSlice, StringPrototypeSplit, @@ -174,7 +173,6 @@ function getErrMessage(message, fn) { const line = call.getLineNumber() - 1; let column = call.getColumnNumber() - 1; let identifier; - let code; if (filename) { identifier = `${filename}${line}${column}`; @@ -199,31 +197,24 @@ function getErrMessage(message, fn) { // errors are handled faster. if (errorStackTraceLimitIsWritable) Error.stackTraceLimit = 0; - if (filename) { - if (decoder === undefined) { - const { StringDecoder } = require('string_decoder'); - decoder = new StringDecoder('utf8'); - } - - // ESM file prop is a file proto. Convert that to path. - // This ensure opensync will not throw ENOENT for ESM files. - const fileProtoPrefix = 'file://'; - if (StringPrototypeStartsWith(filename, fileProtoPrefix)) { - filename = fileURLToPath(filename); - } - - fd = openSync(filename, 'r', 0o666); - // Reset column and message. - ({ 0: column, 1: message } = getCode(fd, line, column)); - // Flush unfinished multi byte characters. - decoder.end(); - } else { - for (let i = 0; i < line; i++) { - code = StringPrototypeSlice(code, - StringPrototypeIndexOf(code, '\n') + 1); - } - ({ 0: column, 1: message } = parseCode(code, column)); + if (decoder === undefined) { + const { StringDecoder } = require('string_decoder'); + decoder = new StringDecoder('utf8'); } + + // ESM file prop is a file proto. Convert that to path. + // This ensure opensync will not throw ENOENT for ESM files. + const fileProtoPrefix = 'file://'; + if (StringPrototypeStartsWith(filename, fileProtoPrefix)) { + filename = fileURLToPath(filename); + } + + fd = openSync(filename, 'r', 0o666); + // Reset column and message. + ({ 0: column, 1: message } = getCode(fd, line, column)); + // Flush unfinished multi byte characters. + decoder.end(); + // Always normalize indentation, otherwise the message could look weird. if (StringPrototypeIncludes(message, '\n')) { if (EOL === '\r\n') {