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

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

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (2 by maintainers)

Commits related to this issue

Most upvoted comments

@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'))

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
    }
})

I started to see the same issue after upgrading to version 10.2. Even using the workaround from @jennifer-shehane jennifer-shehane

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
    }
})

Any ideas? Thanks

I am having the same issue after upgrading to 10.0.2 as well @willoliveira-air @jennifer-shehane . Below is my configuration:

Cypress.on('uncaught:exception', (err) => {
  // returning false here prevents Cypress from
  // failing the test
  cy.log('Cypress detected uncaught exception: ', err);
  console.log('Cypress detected uncaught exception: ', err);
  return false;
});

While the cy.log and console.log statements are working as expected, it seems that Cypress can no longer ignore exceptions.

Using cy.viewport in multiple tests in the same file caused this issue for me; moving it to a before hook sidestepped it.

@alineborak Your error is different than the ResizeObserver one, so you would need to change the regex to look for Script error. Or better, don’t include the NewRelic tracker in your test env.

I also created a fresh bug ticket to shed some light on the issue, as this bug pertains to a newer version of Cypress: https://github.com/cypress-io/cypress/issues/22129

I started to see the same issue after upgrading to version 10.2. Even using the workaround from @jennifer-shehane jennifer-shehane

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
    }
})

Any ideas? Thanks