question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stack trace files point to localhost instead of source files.

See original GitHub issue

When using the code provided below and const loadFromFile = false the events reported in Sentry will have the following stack trace:

Error: test event
  at onClick(http://localhost:43288)
  at Object.Be(http://localhost:43288)
  at Ke(http://localhost:43288)
  at <anonymous>(http://localhost:43288)
  at Er(http://localhost:43288)
  at xr(http://localhost:43288)
  at <anonymous>(http://localhost:43288)
  at Ie(http://localhost:43288)
  at <anonymous>(http://localhost:43288)
  at zr(http://localhost:43288)
  at Jt(http://localhost:43288)
  at Gt(http://localhost:43288)
  at t.unstable_runWithPriority(http://localhost:43288)
  at Vl(http://localhost:43288)
  at Me(http://localhost:43288)
  at Yt(http://localhost:43288)

While setting the option to true const loadFromFile = true the stack trace points to the files, which can be resolved using source maps:

Error: test event
  at onClick(app:///build/static/js/main.a6537570.chunk.js:1:530)
  at Object.Be(app:///build/static/js/2.ef71193e.chunk.js:2:23511)
  at Ke(app:///build/static/js/2.ef71193e.chunk.js:2:23665)
  at ? (app:///build/static/js/2.ef71193e.chunk.js:2:41674)
  at Er(app:///build/static/js/2.ef71193e.chunk.js:2:41768)
  at xr(app:///build/static/js/2.ef71193e.chunk.js:2:42183)
  at ? (app:///build/static/js/2.ef71193e.chunk.js:2:47836)
  at Ie(app:///build/static/js/2.ef71193e.chunk.js:2:123879)
  at ? (app:///build/static/js/2.ef71193e.chunk.js:2:43644)
  at zr(app:///build/static/js/2.ef71193e.chunk.js:2:43674)
  at Jt(app:///build/static/js/2.ef71193e.chunk.js:2:31943)
  at Gt(app:///build/static/js/2.ef71193e.chunk.js:2:31169)
  at t.unstable_runWithPriority(app:///build/static/js/2.ef71193e.chunk.js:2:129860)
  at Vl(app:///build/static/js/2.ef71193e.chunk.js:2:52036)
  at Me(app:///build/static/js/2.ef71193e.chunk.js:2:123618)
  at Yt(app:///build/static/js/2.ef71193e.chunk.js:2:30961)

It is a current requirement to run the application with loadFromFile set to false. Is there a workaround to keep the option to load files from localhost and be able to get meaningful stack traces for events?

Versions + Platform

  • SDK version - @sentry/electron@v4.1.0
  • Electron version - electron@v20.0.0
  • Platform - Windows and MacOS

Additional details

One curious point is that, on both cases, there is an warning from the SDK:

Sentry Logger [warn]: SentryError: An event processor returned null, will not send event.
    at /../../node_modules/@sentry/core/cjs/baseclient.js:590:17

App.js:

import React from "react"
export const Sentry = window.require("@sentry/electron")

Sentry.init({ 
  dsn: "",
  debug: true,
});

export default function App() {
  return (
    <body>
      <center>
        <br/>
        <br/>
        <button onClick={() => {
          console.log("About to call Senty.captureException")
          Sentry.captureException(new Error("test event"))
        }}>
          Capture Exception
        </button>
      </center>
    </body>
  )
}

main.js:

const loadFromFile = false
const { app, BrowserWindow } = require('electron')
const remote = require('@electron/remote/main')
remote.initialize()
const Sentry = require("@sentry/electron")
Sentry.init({ 
  dsn: "",
  release: "sentry-test",
  debug: true
});

let mainWindow, mainContents
let reallyQuit = false
function createWindow(staticServerAddress) {
  mainWindow = new BrowserWindow({
    width: 1400, 
    height: 900,
    minWidth: 750,
    minHeight: 500,
    frame: true,
    backgroundColor: '#1d1d1d',
    title: "electron-sentry-test",
    show: true,
    webPreferences: {
      webviewTag: true,
      webSecurity: false,
      nodeIntegration: true,
      plugins: true,
      contextIsolation: false,      //Required for remote to work
    }
  })
  mainContents = mainWindow.webContents
  mainContents.toggleDevTools()
  remote.enable(mainContents)

  if (loadFromFile) {
    const url = require('url')
    const path = require('path')
    mainWindow.loadURL(
      url.format({
        pathname: path.join(__dirname, 'index.html'),
        protocol: 'file:',
        slashes: true
      })
    )
  } else {
    mainContents.loadURL(staticServerAddress,  {"extraHeaders" : "pragma: no-cache\n"})
  }

  //On Windows, closing the app generate this event.
  mainWindow.on("close", () => {
    if (reallyQuit) {
      mainWindow.destroy()
    }
  })
}

//Simple static file server so we can load the app from localhost: instead of file:, enabling Firebase analytics to work
async function startStaticServer() {

  return new Promise(resolve => {
    const static = require('node-static');
    const http = require('http');
    const fileServer = new static.Server(__dirname);
    const staticServer = http.createServer((req, res) => {
      if (req.url === "/") {
        req.url = "/index.html"
      }
      fileServer.serve(req, res);
    })
    const port = 43288
    staticServer.on("error", err => {
      if (err.code === "EADDRINUSE") {
        //Port is already in use.  We hope that it's another instance of <redacted> and roll with it.
        resolve(`http://localhost:${port}/`)
      } else {
        app.exit("Error creating local static server")
      }
    })
    try {
      staticServer.listen(port, "127.0.0.1", () => {
        resolve(`http://localhost:${port}/`)
      });
    }
    catch (err) {
    }
  })
}

app.on('ready', async () => {
  const staticServerAddress = await startStaticServer()
  createWindow(staticServerAddress)
})

app.on("before-quit", evt => {reallyQuit = true})
app.on("will-quit", () => {app.exit(0)})
app.on("window-all-closed", () => {if (process.platform !== 'darwin') {app.exit(0)}})

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
toschlogcommented, Nov 30, 2022

Hello, @timfish! I’m glad to see this item logged and tracked. I’m eager to see it fixed; I hope it’s not too complicated a change.

Thanks,

  • Matt
0reactions
toschlogcommented, Dec 7, 2022

Instead of using npm run electron try this:

  1. run “npm run build-electron-dev”
  2. cd to dist/win-unpacked
  3. Run “Hearo.exe”

Then if that works:

  1. Click on the “Capture Exception” button

What OS are you building on? I may not have includes the files needed to build on Mac.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native Stack Traces that point to original files
Answering my own question. I dug into the react-native code and discovered that LogBox symbolicates stack traces by making calls to the ...
Read more >
4 Reasons Why Your Source Maps are Broken
Missing original source files​​ Parts of the transformation are clearly working; for example, error stack traces now mention your original ...
Read more >
Java Stack Trace: How to Read and Understand to Debug ...
A Java stack trace is a very useful debugging tool. Learn more about what a stack trace is, how it works, and how...
Read more >
KJS / IR: no kotlin source files in error stack trace : KT-39447
Run test via gutter icon (choose nodeTest ). With kotlin.js.compiler=ir you will see only paths to Javascript files in the error stack trace....
Read more >
Resolving minified production stack traces with StackTrace. ...
To use StackTrace.JS you need the stack trace string obtained from production and a source maps file for the code that ran on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found