Skip to content

Commit

Permalink
debug logs for helping with client error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Dec 6, 2023
1 parent 76c3653 commit 5734d31
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions server/src/routes/rootRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ rootRouter.post('/api/error/client', async (req, res) => {
const originalStack =
typeof stack === 'string'
? await Promise.all(
stack.split('\n').map(async (stackLine) => {
stack.split('\n').map(async (stackLine, i) => {
const match = stackLine.match(
/at (.+) \(https?:\/\/([^/]+)\/(.+\.js):(\d+):(\d+)\)/,
)
log.debug(HELPERS.client, { match, stackLine })
if (match) {
const [, functionName, , file, line, column] = match
const [full, functionName, host, file, line, column] = match
const foundStack = await SourceMapConsumer.with(
await fs.promises.readFile(
resolve(__dirname, '../../../dist', `${file}.map`),
Expand All @@ -77,6 +78,21 @@ rootRouter.post('/api/error/client', async (req, res) => {
if (foundStack) {
return foundStack
}
log.warn(HELPERS.client, 'Unable to find source map', {
full,
functionName,
host,
file,
line,
column,
})
}
if (i > 0) {
log.warn(
HELPERS.client,
'Regex missed for stack line:',
stackLine,
)
}
return stackLine
}),
Expand Down

0 comments on commit 5734d31

Please sign in to comment.