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.

Missing stacktrace in renderer process when using Node.js API integration

See original GitHub issue

Versions + Platform

  • SDK version - @sentry/electron@v2.4.0
  • Electron version - electron@v11.0.4
  • Platform - macOS

Description

When capturing a exception thrown by the Node integration in the renderer process, the reported stacktrace is empty.

Sample code to reproduce:

  const exec = promisify(childProcess.exec);
  const command = `commandThatFails`;
  let stdout: string;
  try {
    const response = await exec(command);
    stdout = response.stdout;
  } catch (error) {
    console.log('got error', error);
    stdout = error.stdout;
    if (!stdout) {
      Sentry.captureException(error);
    }
  }

The console prints the following (we can see here the value of error.stack):

got error Error: Command failed: commandThatFails
/bin/sh: commandThatFails: command not found

    at ChildProcess.exithandler (child_process.js:312)
    at ChildProcess.emit (events.js:315)
    at maybeClose (internal/child_process.js:1021)
    at Socket.<anonymous> (internal/child_process.js:443)
    at Socket.emit (events.js:315)
    at Pipe.<anonymous> (net.js:674)

The error is correctly reported when calling Sentry.captureException(error) but in the Sentry web interface the stacktrace is empty. Only the first two lines appear:

Command failed: commandThatFails
/bin/sh: commandThatFails: command not found

It seems the Sentry client tries to parse the stack as a Chrome stack, but as the error comes from the Node integration, the format does not match and all frames are skipped.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
timfishcommented, Mar 9, 2021

Sorry, I haven’t been very clear there!

I understand your issue and it is caused by the fact that @sentry/node is not used in the renderer.

I’m saying that to fix your issue, @sentry/electron needs to be modified to use @sentry/node in the renderer and we need to ensure that exceptions are not caught twice.

0reactions
clemp6rcommented, Mar 10, 2021

Besides, I looked again at my sample stacktrace and it seems there is nothing interesting into, it apart technical framework frames. No function from my application appear. I may have to create new Error objects if I want to have a good stracktrace. Or it is Sentry’s responsiblity?

  try {
    const response = await exec(command);
  } catch (error) {
    console.log('got error', error);
    stdout = error.stdout;
    if (!stdout) {
      const wrappedError = new Error('Unable to run command: ' + error);
      Sentry.captureException(wrappedError);
    }
    ...
Read more comments on GitHub >

github_iconTop Results From Across the Web

Missing stack trace on node.js uncaughtException generated ...
Disclaimer: I know that using process.on('uncaughtException') is a very, very bad thing and I will be punished but using domains is not an ......
Read more >
Events | Node.js v19.3.0 Documentation
When a listener is registered using the eventEmitter.on() method, ... the error is thrown, a stack trace is printed, and the Node.js process...
Read more >
Error Reporting - Node.js client library - Google Cloud
The stack trace associated with an error can be viewed in the error reporting console. If the errors.report method is given an ErrorMessage ......
Read more >
Server-Side Rendering - Vite
SSR specifically refers to front-end frameworks (for example React, Preact, Vue, and Svelte) that support running the same application in Node.js, pre-rendering ......
Read more >
How does JavaScript and JavaScript engine work in ... - Medium
If any function call at a given stack frame produces an error, JavaScript will print a stack trace which is nothing but a...
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