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.

Cypress.on('uncaught:exception') receives CypressError instead of thrown error

See original GitHub issue

Current behavior:

This might be a regression with Cypress 5.0.

I have a global catch for ResizeObserver loop limit exceeded in my support/index.js file.

const resizeObserverLoopErrRe = /^ResizeObserver loop limit exceeded/

Cypress.on('uncaught:exception', err => {
  if (resizeObserverLoopErrRe.test(err.message)) {
    return false
  }
})

As of version 5, I started noticing that when this error occurs, the handler will receive a CypressError instance, instead of the original error containing the above message. This therefore makes the tests fail, and returns the usual info message about this error:


The following error originated from your application code, not from Cypress.

  > ResizeObserver loop limit exceeded

When Cypress detects uncaught errors originating from your application it will automatically fail the current test.

This behavior is configurable, and you can choose to turn this off by listening to the `uncaught:exception` event.

https://on.cypress.io/uncaught-exception-from-application

Desired behavior:

The handler should receive the actual globally thrown error, as it previously did.

Test code to reproduce

https://github.com/vicrep/cypress-test-tiny/pull/1/files

Versions

Cypress: 5.0.0 Browser: Both on Electron and Chrome (didn’t test others) OS: Reproed on macOS and Linux

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
hon2acommented, Dec 13, 2021

@jennifer-shehane Please note that the regular expression you posted actually matches “any text starting with a character that is not one of () ORcdeilmoprstvxz” (all characters present in (ResizeObserver loop limit exceeded)), which is patently wrong and causes a lot of other errors to be possibly swallowed.

A simple way to safely-enough ignore just this specific error is:

Cypress.on('uncaught:exception', err => !err.message.includes('ResizeObserver loop limit exceeded'))
12reactions
jennifer-shehanecommented, Aug 27, 2020

We changed how the errors are constructed in 4.6.0+, you’ll need to upgrade your Regex to match the newly constructed error:

const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/
Cypress.on('uncaught:exception', (err) => {
    /* returning false here prevents Cypress from failing the test */
    if (resizeObserverLoopErrRe.test(err.message)) {
        return false
    }
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress.on('uncaught:exception') No Longer Preventing Tests ...
Cypress.on ('uncaught:exception') receives CypressError instead of ... error was being thrown in the Cypress test runner itself, rather than ...
Read more >
Cypress Uncaught Assertion Error despite cy ... - Stack Overflow
Uncaught Error: Script error. Cypress detected that an uncaught error was thrown from a cross origin script. We cannot provide you the stack...
Read more >
Error Messages | Cypress Documentation
Cypress detected that an uncaught error was thrown from a cross-origin script. Browser Errors; The browser process running your tests just exited unexpectedly ......
Read more >
How to handle Errors in Cypress | BrowserStack
Error handling is essential to avoid false failed tests. Learn different ways of Cypress Error and Exception Handling techniques with this ...
Read more >
Handle Service Unavailable and Uncaught Exception in ...
In this video, I have explained how to solve handle service unavailable error and Uncaught Exception in Cypress.
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