Cypress: "Cannot set property 'err' of undefined" error occurs in place of other errors during automatic test-reruns on file save.

Created on 3 Jul 2020  Â·  14Comments  Â·  Source: cypress-io/cypress

Current behavior:

When running tests locally through cypress open, and when interrupting tests by saving files (forcing a re-run), any failures occurred during the run can trigger this message:

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

  > Cannot set property 'err' of undefined

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. Learn more

The error is not really originating from the application; it's occurring within hookFailed at https://github.com/cypress-io/cypress/blob/4cfcae28f097e013ffe7dc7419905eccf1022709/packages/driver/src/cypress/runner.js#L526. Both getTest() and getTestFromHookOrFindTest(hook) end up returning undefined.

I've seen this on two very different projects.

  • At work, which is a custom server + Webpack setup, webpack/React, running on MacOS.
  • At home, on a personal project running Next.js, running on Windows (Powershell). This project is linked below.

Desired behavior:

The test fails with the normal readable stack trace.

Test code to reproduce

This is easily reproducible on this project (created a branch with a failing spec):
https://github.com/primitiveconcept/ludumdare46/tree/cypress/err-of-undefined/client

  • Run npm run cy:dev for server + Cypress
  • Run the filesystem.spec.ts spec
  • Save the filesystem.spec.ts while the test is running. Reproduces around 25% of the time, may require a few tries.

If needed, I can try to come up with a minimal reproduction, but this isn't a very complex project. The server isn't required for the tests.

Versions

Cypress versions: Can reproduce on 4.9.0. Cannot reproduce on 4.5.0. Other versions are unstable for various reasons on the example project. At work, this started occurring on 4.6.0.
OS: MacOS + Windows
Browser: Chrome + Electron

┆Issue is synchronized with this Jira Bug by Unito

internal-priority pkdriver hooks ↪ bug

Most helpful comment

The bug is annoying, but I'm more concerned that the error message is lying to us, implying that the error came from our code when it really came from cypress. Should there be another issue to address that?

All 14 comments

I can confirm that this issue shows up (not sporadic, but as soon as something is "hot-reloaded/refreshed"), and does not appear in 4.5.0.

I can verify this behavior - if you save the file really early in the test running, the test is not defined when reading the global afterEach hook, so it throws this error.

Can reproduce from the code in this repo as explaind: https://github.com/primitiveconcept/ludumdare46/tree/cypress/err-of-undefined/client

If I run this in 4.5, the tests keep locking up for me, so I wouldn't say 4.5 is a working version.

I always get this when it's detecting a change and re-running the tests. Even if the previous test-run has finished running a long time ago

Should I open a separate issue for the The following error originated from your application code, not from Cypress. message?

At work, this was introduced with an upgrade to 4.6.0, but we just assumed it was something in our code causing it. I'm guessing that's why it hasn't been reported until now.

The bug is annoying, but I'm more concerned that the error message is lying to us, implying that the error came from our code when it really came from cypress. Should there be another issue to address that?

Same issue with 4.11.0.

This error is being thrown from here: https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cypress/runner.js#L550 Sometimes the test is not defined at this point when we are trying to set test.err.

So the question is, why is it failing to find the test here in this hook?

It just doesn't have this currentTest property defined when we're trying to read it.

Screen Shot 2020-07-22 at 5 40 21 PM

I can get this test to be undefined in a lot of circumstances, when saving the file, but there's a special time and situation where it hits that it makes the error bubble up incorrectly as an application error. I'm having a harder time reducing the use case to a small example for this. It is reproducible from here: https://github.com/primitiveconcept/ludumdare46/tree/cypress/err-of-undefined/client

For me it happens every time after the first re-run. The initial run passes with no issues and all the subsequent are failing with this error, even if no files are changed - just a simple re-run triggered by the button in cypress UI.

I end up returning false from the 'uncaught:exception' hook to suppress this error temporarily, so the tests are passing on re-run.

"cypress": "4.10.0"

I could cut that example down quite a bit if that would help.

This is happening to me after upgrading from v4.10.0 to v4.11.0.

I'm working on this. We might have already fixed as part of https://github.com/cypress-io/cypress/pull/8113 (unfortunately didn't make it into last release), and I'm working on getting a reproducible test case to verify

confirmed the work for this is done in #8113

Scheduled to release in version 4.12.1

Released in 4.12.1.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v4.12.1, please open a new issue.

If you're still experiencing this issue after upgrading to 4.12.1, please see this issue: #8189 and the new PR proposed to fix the issue: #8193

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stormherz picture stormherz  Â·  3Comments

jennifer-shehane picture jennifer-shehane  Â·  3Comments

tahayk picture tahayk  Â·  3Comments

EirikBirkeland picture EirikBirkeland  Â·  3Comments

egucciar picture egucciar  Â·  3Comments