The Wayback Machine - https://web.archive.org/web/20201203174849/https://github.com/gatsbyjs/gatsby/issues/24863
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stacktraces from async functions break error reporting #24863

Open
mathewTH opened this issue Jun 8, 2020 · 7 comments · May be fixed by #27262
Open

stacktraces from async functions break error reporting #24863

mathewTH opened this issue Jun 8, 2020 · 7 comments · May be fixed by #27262

Comments

@mathewTH
Copy link

@mathewTH mathewTH commented Jun 8, 2020

Description

Error while processing an error generated by a source plugin.
Gatsby tries to open an invalid filename from the stack trace. This causes a new error that hides the original plugin error.

Steps to reproduce

I'm unsure of exact steps, although if necessary I might be able to create some. But from what I have seen, I believe it could be triggered when a plugin throws an exception with a stack trace entry which contains gatsby-node but is not a valid filename. In my case the invalid filename is async C:\Users\Mathew\Development\dive-club-gatsby\node_modules\gatsby-source-google-spreadsheet\gatsby-node.js.

Expected result

Something like the following:

success Downloading remote files - 1.524s - 2/2 1.31/s

 ERROR #11321  PLUGIN


"gatsby-source-google-spreadsheet" threw an error while running the sourceNodes lifecycle:

Cannot read property 'map' of undefined



  TypeError: Cannot read property 'map' of undefined

  - sheets.js:216 sheetToTable
    [dive-club-gatsby]/[node-sheets]/lib/sheets.js:216:4

  - Array.map

  - sheets.js:191 Sheets.tables
    [dive-club-gatsby]/[node-sheets]/lib/sheets.js:191:37

  - task_queues.js:97 processTicksAndRejections
    internal/process/task_queues.js:97:5

  - gatsby-node.js:27
    [dive-club-gatsby]/[gatsby-source-google-spreadsheet]/gatsby-node.js:27:20

  - async Promise.all


success source and transform nodes - 12.578s

I produced that output by modifying api-runner-node.js, adding

if(/google-spreadsheet\\gatsby-node/.test(file.fileName)){
    file = null;
}

after line 383 const file = stackTrace.parse(err).find(file => /gatsby-node/.test(file.fileName)); (changing const to let too) and before if (file) {.

Actual result

UNHANDLED REJECTION ENOENT: no such file or directory, open 'async C:\Users\Mathew\Development\dive-club-gatsby\node_modules\gatsby-source-google-spreadsheet\gatsby-node.js'



  Error: ENOENT: no such file or directory, open 'async C:\Users\Mathew\Development\dive-club-gatsby\node_modules\gatsby-source-google-spreadsheet\gatsby-node.js'

  - api-runner-node.js:395
    [dive-club-gatsby]/[gatsby]/dist/utils/api-runner-node.js:395:25

  - util.js:16 tryCatcher
    [dive-club-gatsby]/[bluebird]/js/release/util.js:16:23

  - promise.js:547 Promise._settlePromiseFromHandler
    [dive-club-gatsby]/[bluebird]/js/release/promise.js:547:31


  - promise.js:604 Promise._settlePromise
    [dive-club-gatsby]/[bluebird]/js/release/promise.js:604:18

  - promise.js:649 Promise._settlePromise0
    [dive-club-gatsby]/[bluebird]/js/release/promise.js:649:10

  - promise.js:725 Promise._settlePromises
    [dive-club-gatsby]/[bluebird]/js/release/promise.js:725:18

  - async.js:93 _drainQueueStep
    [dive-club-gatsby]/[bluebird]/js/release/async.js:93:12

  - async.js:86 _drainQueue
    [dive-club-gatsby]/[bluebird]/js/release/async.js:86:9

  - async.js:102 Async._drainQueues
    [dive-club-gatsby]/[bluebird]/js/release/async.js:102:5

  - async.js:15 Immediate.Async.drainQueues [as _onImmediate]
    [dive-club-gatsby]/[bluebird]/js/release/async.js:15:14

  - timers.js:456 processImmediate
    internal/timers.js:456:21

not finished source and transform nodes - 11.189s

Environment

  System:
    OS: Windows 10 10.0.18362
    CPU: (4) x64 Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz
  Binaries:
    Node: 12.16.1 - C:\Program Files\nodejs\node.EXE
    npm: 6.13.4 - C:\Program Files\nodejs\npm.CMD
  Languages:
    Python: 3.7.3 - /c/Program Files/Python37/python
  Browsers:
    Edge: 44.18362.449.0
  npmPackages:
    gatsby: ^2.21.22 => 2.21.22
    gatsby-image: ^2.4.3 => 2.4.3
    gatsby-plugin-manifest: ^2.4.2 => 2.4.2
    gatsby-plugin-offline: ^3.2.1 => 3.2.1
    gatsby-plugin-purgecss: ^5.0.0 => 5.0.0
    gatsby-plugin-react-helmet: ^3.3.1 => 3.3.1
    gatsby-plugin-sass: ^2.3.1 => 2.3.1
    gatsby-plugin-sharp: ^2.6.2 => 2.6.2
    gatsby-remark-images: ^3.3.8 => 3.3.8
    gatsby-source-filesystem: ^2.3.1 => 2.3.1
    gatsby-source-google-docs: ^2.0.0-beta.9 => 2.0.0-beta.9
    gatsby-source-google-spreadsheet: ^2.0.0 => 2.0.0
    gatsby-transformer-remark: ^2.8.13 => 2.8.13
    gatsby-transformer-sharp: ^2.5.2 => 2.5.2
  npmGlobalPackages:
    gatsby-cli: 2.12.44
@danabrit
Copy link
Contributor

@danabrit danabrit commented Jun 9, 2020

Hi @mathewTH !

Sorry to hear you're running into an issue. To help us best begin debugging the underlying cause, it is incredibly helpful if you're able to create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it.

If you're up for it, we'd very much appreciate if you could provide a minimal reproduction and we'll be able to take another look.

Thanks for using Gatsby! 💜

@mathewTH
Copy link
Author

@mathewTH mathewTH commented Jun 10, 2020

I have reproduced the bug using https://github.com/mathewTH/gatsby-bug-24863-repro
However, since the plugin that exposed the gatsby bug for me is using google sheets api, a service account is needed (unless I've missed another way for a google api key to be attached to the request). The sheet I'm using for repro is public, so any service account with sheets api turned on will work. I could supply a working .env file for testing, if necessary.

@ascorbic
Copy link
Member

@ascorbic ascorbic commented Jun 18, 2020

Hi @mathewTH . I'm a bit confused here, because it seems to be doing what it's supposed to be doing. Does the file C:\Users\Mathew\Development\dive-club-gatsby\node_modules\gatsby-source-google-spreadsheet\gatsby-node.js actually exist? The code there is trying to load that file so that it can highlight the context of the error. I'm confused as to why the stack frame has that filename, but the file doesn't exist.

@mathewTH
Copy link
Author

@mathewTH mathewTH commented Jun 23, 2020

@github-actions
Copy link

@github-actions github-actions bot commented Jul 14, 2020

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

@github-actions github-actions bot added the stale? label Jul 14, 2020
@freiksenet
Copy link
Contributor

@freiksenet freiksenet commented Jul 15, 2020

@mathewTH Thank you for a great reproduction! I've confirmed this bug on the latest gatsby. This seems to be a problem with stacktrace library that we are using. I'll debug/fix it later if I have time.

To fix this problem one would replace stacktrace library with a inlined version that works for async functions. In addition, adding a test to error reporting would be useful.

@freiksenet freiksenet changed the title 'ENOENT: no such file or directory, open' while processing source plugin error, hides original error stacktraces from async functions break error reporting Jul 15, 2020
@fakeharahman
Copy link

@fakeharahman fakeharahman commented Aug 18, 2020

Hi, I'm new to open source, can I try to solve this issue?

@tysng tysng linked a pull request that will close this issue Oct 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.