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.

Better document error handling in hooks

See original GitHub issue

Environment (please complete the following information):

  • WebdriverIO version: [e.g. 4.13.2]
  • Mode: testrunner
  • If WDIO Testrunner, running sync/async: sync & async
  • Node.js version: 12
  • Browser name and version: Chrome 85
  • Platform name and version: Windows 10

Describe the bug I was having trouble with some tests when I realized, that my onPrepare hook was throwing an error. The test still ran as usual but since my backend wasn’t running, I was getting misleading errors.

To Reproduce Add this hook to your config.

onPrepare: async function (config, capabilities) {
      throw new Error("error")
}

// or 

onPrepare: function (config, capabilities) {
      throw new Error("error")
}

Log

...
2020-09-25T10:57:13.724Z ERROR @wdio/cli:utils: Error in hook: Error: error
    at Object.onPrepare (C:\Development\anvajo datalab\test\config\wdio.conf.ts:251:13)
    at C:\Development\anvajo datalab\node_modules\@wdio\cli\build\utils.js:95:14
    at Array.map (<anonymous>)
    at runLauncherHook (C:\Development\anvajo datalab\node_modules\@wdio\cli\build\utils.js:93:27)
    at Launcher.run (C:\Development\anvajo datalab\node_modules\@wdio\cli\build\launcher.js:78:41)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Starting ChromeDriver 85.0.4183.87 (cd6713ebf92fa1cacc0f1a598df280093af0c5d7-refs/branch-heads/4183@{#1689}) on port 9515
...

Expected behavior An error in onPrepare hook should abort the test.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
christian-bromanncommented, Nov 24, 2020

FYI: the solution to use SevereServiceError in TypeScript and WebdriverIO sync mode is by using require to avoid type clashings.

const { SevereServiceError } = require('webdriverio')
2reactions
christian-bromanncommented, Sep 25, 2020

it shouldn’t if you explicitly set @wdio/sync types:

    "types": [
      "node",
      "@wdio/mocha-framework",
      "@wdio/sync"
    ],
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error Handling in React Hooks - Medium
Error Handling in Hooks is quite Simple. In this article, we are going to demonstrate how to handle errors in React Hooks.
Read more >
Hooked with React - Error handling and loading state in react ...
We created a new state called error using useState . It was set in the catch block. try, catch is the usual way...
Read more >
React Error Handling and Logging Best Practices
This article will go over best practices for error handling and logging ... and asynchronous code using the useErrorHandler() custom hook.
Read more >
Handle errors in React components like a pro
When you are writing a react application you have two ways to handling errors: Using try/catch block in each component. Using React Error ......
Read more >
React error handling with react-error-boundary - LogRocket Blog
useErrorHandler Hook ; handleError function, which was returned by the ; useErrorHandle Hook. This way, our error boundaries are more useful.
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