sentry-javascript: Source code was not found for index.js

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other:

Version:

4.4.1

Description

The following event capturing code will produce an error in Sentry while parsing the event: Source code was not found for /.../index.js

const Sentry = require('@sentry/node');

Sentry.init({ dsn: 'https://5d29[...]58f@sentry.io/13[...]6' });

(async () => {
  const sentryEvent = await Sentry.Parsers.parseError(new Error('Test'));
  Sentry.captureEvent(sentryEvent);
})();

Here is how the event looks like in Sentry: Sentry Event Screenshot

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 12
  • Comments: 28 (11 by maintainers)

Most upvoted comments

@guischdi the reason why you get this error is that local file paths are not reachable to remote servers. Sentry is trying to fetch and resolve /something/local/src/app.js and read the source-code from it to provide better error mappings (it works in the same way with sourcemap files).

To upload your files, you can use our CLI https://docs.sentry.io/cli/ or Webpack plugin https://github.com/getsentry/sentry-webpack-plugin

Here are some old docs on source maps, but the concept is the same for new SDK https://docs.sentry.io/clients/node/sourcemaps/ (it all applies in the same way to your current issue).

There’s also an existing integration you can use to rewrite paths in every frame https://github.com/getsentry/sentry-javascript/blob/master/packages/core/src/integrations/pluggable/rewriteframes.ts

So for example:

Sentry.init({
  dsn: "https://363a337c11a64611be4845ad6e24f3ac@sentry.io/297378",
  integrations: [new Sentry.Integrations.RewriteFrames()]
});

Will change /something/local/src/app.js to app:///app.js (app:/// is our internal prefix), so when you upload app.js to your sentry release artifacts, it will be read correctly without a need to fetch external files.

Basically what you need to do is:

  • set a release in init call
  • upload your sources to the same release in the Sentry
  • make sure that frames in errors you catch correspond to those from your upload files

Hope it clears some things for you. Feel free to ask anything if you need more help.

Ok, so this looks like a UX bug to me. In my opinion it should (at least for Node.js projects) be only a warning and it must not say Source code was not found but something like Source maps were not found. This would have prevented an issue with a history of more than a year 😉 If you want you can reopen this issue as a report for whoever works on the frontend/display part, or just leave it closed and report this misunderstanding to them. Thanks a lot for finally clarifying this!

@guischdi sorry for such a late response. I lost a track a bit. Can you refresh my memory what’s going on here and provide some sample events?

Can you post a direct link to the event?

(you also missed some paths in the stacktrace screenshot you masked earlier 😅)

Any particular reason why you don’t use Sentry.captureException directly, but rather want to create your own event?

@guischdi we are investigating why it’s behaving like this (2 consecutive frames with the same url triggers this). In the meantime, you can turn off “Enable JavaScript Source Fetching” in your project’s settings, eg. https://sentry.io/settings/kamil-ogorek/projects/testing-project/ It’s node app, so there’s no point in doing that.

I’m running Sentry self-hosted and using @sentry/node 5.4.3

Heres my code:

// file: <path>/code/cli
const Sentry = require('@sentry/node');
Sentry.init({ dsn: process.env.SENTRY_DSN });
function test () {
  throw new Error('test');
}
test();

I’m also getting this error:

image

And here is the stack:

Error: test
  File "<path>/code/cli", line 10, col 9, in test
    throw new Error('test');
  File "<path>/code/cli", line 13, col 1, in Object.<anonymous>
    test();
  File "internal/modules/cjs/loader.js", line 1063, col 30, in Module._compile
  File "internal/modules/cjs/loader.js", line 1103, col 10, in Module._extensions..js
  File "internal/modules/cjs/loader.js", line 914, col 32, in Module.load
  File "internal/modules/cjs/loader.js", line 822, col 14, in Module._load
  File "internal/modules/cjs/loader.js", line 1143, col 12, in Module.runMain
  File "internal/main/run_main_module.js", line 16, col 11, in null.<anonymous>

Odd, that works for me just fine. Anyways, we’ll try to investigate why that happens, although I cannot promise when it happens, as it’s not major issue preventing anything from working. Will keep you posted!

@guischdi just to confirm, this is raw node js file right? no webpack, no compilation, no source maps. Just one index.js file with 2 different calls on different lines? Can you provide the content of this file if possible?

@guischdi can you past full link to both events? Not shareable ones? I can access them through admin permissions.

Also, I’ll be out of office for the next 3 weeks, so I’ll try to get back to this one when I’ll come back.