Skip to content

Commit

Permalink
fix: better regex for mapping minified errors
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Jan 12, 2024
1 parent 8f1d9e0 commit cd0c28b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 4 additions & 5 deletions server/src/routes/rootRouter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const express = require('express')
const fs = require('fs')
const { resolve } = require('path')
const { resolve, join } = require('path')
const { SourceMapConsumer } = require('source-map')
const config = require('@rm/config')
const { log, HELPERS } = require('@rm/logger')
Expand Down Expand Up @@ -52,14 +52,14 @@ rootRouter.post('/api/error/client', async (req, res) => {
? await Promise.all(
stack.split('\n').map(async (stackLine, i) => {
const match = stackLine.match(
/at (.+) \(https?:\/\/([^/]+)\/(.+\.js):(\d+):(\d+)\)/,
/at (.+) \((\/.+\.js):(\d+):(\d+)\)/,
)
log.debug(HELPERS.client, { match, stackLine })
if (match) {
const [full, functionName, host, file, line, column] = match
const [full, functionName, file, line, column] = match
const foundStack = await SourceMapConsumer.with(
await fs.promises.readFile(
resolve(__dirname, '../../../dist', `${file}.map`),
join(__dirname, '../../../dist', `${file}.map`),
'utf8',
),
null,
Expand All @@ -81,7 +81,6 @@ rootRouter.post('/api/error/client', async (req, res) => {
log.warn(HELPERS.client, 'Unable to find source map', {
full,
functionName,
host,
file,
line,
column,
Expand Down
5 changes: 4 additions & 1 deletion src/components/ErrorBoundary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ class ErrorBoundary extends React.Component {
await Fetch.sendError({
cause: error.cause,
message: error.message,
stack: error?.stack,
stack: error?.stack?.replace(
/(http|https):\/\/[a-z0-9.]+(:[0-9]+)?/g,
'',
),
name: error.name,
uuid: this.state.uuid,
})
Expand Down

0 comments on commit cd0c28b

Please sign in to comment.