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.

pact-node throws promise rejection errors

See original GitHub issue

Software versions

  • OS: Mac OSX 10.13.6
  • Library version: @pact-foundation/pact-node@6.20.0
  • Node Version: v8.11.0

Expected behaviour

Using pact-node shouldn’t affect the behaviour of unhandled promise rejections.

Actual behaviour

When pact-node is included in a project, any unhandled promise rejections result in the following error:

/Users/work/office/pact/example/node_modules/@pact-foundation/pact-node/standalone/install.js:263
    throw new Error(chalk.red("Unhandled Promise Rejection: " + e));
    ^

Error: Unhandled Promise Rejection: Boom
    at process.<anonymous> (/Users/work/office/pact/example/node_modules/@pact-foundation/pact-node/standalone/install.js:263:11)
    at emitTwo (events.js:126:13)
    at process.emit (events.js:214:7)
    at emitPendingUnhandledRejections (internal/process/promises.js:108:22)
    at process._tickCallback (internal/process/next_tick.js:189:7)

This is a problem, because it prevents the development of APIs that return rejecting promises, and also it is swallowing any supporting information about where the rejection came from.

It’s especially a problem if the test setup script requires pact, as then any unhandled rejections anywhere in the code will fail.

Steps to reproduce

Clone this repository:

https://github.com/TimothyJones/pact-node-rejection-issue

Then:

npm install && npm run test

Relevant log files

None, but the error comes from this line:

https://github.com/pact-foundation/pact-node/blob/master/standalone/install.ts#L309

I’m not sure why the handler exists - can anyone shed any light?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

7reactions
mboudreaucommented, Jan 3, 2019

I’m sorry everyone for causing this issue, it was a refactor that I didn’t properly think through. I’ve now removed the global promise rejection handler and instead just wrapped the promise rejection with a function that handles it. Fix is available in version 6.20.2. Cheers.

1reaction
mefellowscommented, Jan 3, 2019

Thanks for fixing Michel!

Read more comments on GitHub >

github_iconTop Results From Across the Web

pact-node throws promise rejection errors · Issue #132 - GitHub
This is a problem, because it prevents the development of APIs that return rejecting promises, and also it is swallowing any supporting ...
Read more >
Troubleshooting | Pact Docs
This test will fail, because the use of await will throw if the promise is rejected. To correct this test, you should pass...
Read more >
Rejected Promise breaks loop despite catch - node.js
Looking at the code and error, I believe this comes from the "createNewUser" function. I'm not sure why the code breaks - I...
Read more >
@pact-foundation/pact-node - npm
Start using @pact-foundation/pact-node in your project by running `npm i ... or is json, error will be an object describing // the result...
Read more >
How to use the @pact-foundation/pact-node.logLevel function in ...
if (isEmpty(this.opts.provider)) { throw new Error("You must specify a Provider for this pact."); } this.server = serviceFactory.
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