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

Fix onError hook #512

Merged
merged 2 commits into from
Nov 22, 2019
Merged

Fix onError hook #512

merged 2 commits into from
Nov 22, 2019

Conversation

ehmicky
Copy link
Contributor

@ehmicky ehmicky commented Nov 22, 2019

onError hooks receive the error instance as argument:

module.exports = {
  name: 'netlify-plugin-example',
  onError({ error }) {
    console.error(error)
  }
}

However plugins are spawned as child processes. The parent process communicates to them through child_process ipc which uses JSON as the message format. This leads to error instances being converted to plain objects, which makes them lose their Error prototype, message, name and stack properties.

This PR fixes this by serializing and parsing error instances ourselves.

Note that Node.js added support for v8 serialization (based on the HTML structured clone algorithm) yesterday! :D This is available in Node 13.2.0. Unfortunately the Node.js version of the parent process is the same as child processes, so we need to support Node down to 8.3.0 (see ongoing discussion #81).

Tagging @sdras since this is part of the ongoing "error handling" thread.

@codecov
Copy link

codecov bot commented Nov 22, 2019

Codecov Report

Merging #512 into master will decrease coverage by 0.17%.
The diff coverage is 57.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #512      +/-   ##
==========================================
- Coverage   90.74%   90.56%   -0.18%     
==========================================
  Files          47       47              
  Lines        1080     1092      +12     
  Branches      123      127       +4     
==========================================
+ Hits          980      989       +9     
- Misses         74       77       +3     
  Partials       26       26
Flag Coverage Δ
#macOS 90.1% <57.14%> (-0.45%) ⬇️
#node_13 90.56% <57.14%> (-0.18%) ⬇️
#node_8_3_0 90.1% <57.14%> (-0.45%) ⬇️
#ubuntu 90.1% <57.14%> (-0.45%) ⬇️
#windows 86.06% <57.14%> (?)
Impacted Files Coverage Δ
packages/build/src/plugins/ipc.js 83.33% <57.14%> (-11.12%) ⬇️
packages/build/src/log/main.js 96.93% <0%> (+1.02%) ⬆️
packages/build/src/telemetry/plugins.js 63.33% <0%> (+6.66%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d1ec077...6061f74. Read the comment docs.

@ehmicky ehmicky merged commit 122999f into master Nov 22, 2019
@ehmicky ehmicky deleted the fix/fix-on-error-hook branch November 22, 2019 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant