Better document error handling in hooks
See original GitHub issueEnvironment (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:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
FYI: the solution to use
SevereServiceError
in TypeScript and WebdriverIO sync mode is by using require to avoid type clashings.it shouldn’t if you explicitly set
@wdio/sync
types: