Skip to content

Commit

Permalink
Always return original stack trace
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl committed Oct 31, 2024
1 parent be9b919 commit c3c3fe1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/stacktrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ const STACK_TRACE_LINE_REGEX = /^([A-Za-z0-9]*)@(.*):([0-9]+):([0-9]+)/
*/
export async function decodeMinifiedStackTrace (stack, sourceMaps = {}) {
let decodedStack = ''
let decoded = false
for (const line of stack.split('\n')) {
try {
const stackLine = line.trim()
const stackLineParts = stackLine?.match(STACK_TRACE_LINE_REGEX)
if (stackLineParts) {
const [stackFile, stackLine, stackColumn] = stackLineParts.slice(2)
if (!stackFile || !stackLine || !stackColumn) throw new Error('Unsupported stack line ' + JSON.stringify(stackLineParts))
if (!stackFile || !stackLine || !stackColumn) throw new Error('Unsupported stack line')
if (
(
!stackFile.startsWith(process.env.NEXT_PUBLIC_ASSET_PREFIX) &&
Expand All @@ -35,13 +36,20 @@ export async function decodeMinifiedStackTrace (stack, sourceMaps = {}) {
column: parseInt(stackColumn)
})
const { source, name, line, column } = map
if (!source || line === undefined) throw new Error('Unsupported stack line')
decodedStack += `${name || ''}@${source}:${line}:${column}\n`
decoded = true
continue
}
} catch (e) {
console.error('Cannot decode stack line', e)
}
decodedStack += `${line}\n`
}

if (decoded) {
decodedStack = `Decoded stacktrace:\n${decodedStack}\n\nOriginal stack trace:\n${stack}`
}

return decodedStack
}

0 comments on commit c3c3fe1

Please sign in to comment.