Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
threehams opened this issue Jul 2, 2020 · 14 comments · Fixed by #8113 · May be fixed by Omrisnyk/npm-lockfiles#145 or Omrisnyk/npm-lockfiles#164
Assignees
Labels
pkg/driver This is due to an issue in the packages/driver directory topic: hooks ↪ type: bug

Comments

@threehams
Copy link

threehams commented Jul 2, 2020

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

. 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

@SleeplessByte
Copy link

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.

@jennifer-shehane
Copy link
Member

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.

@jennifer-shehane jennifer-shehane added the pkg/driver This is due to an issue in the packages/driver directory label Jul 6, 2020
@cypress-bot cypress-bot bot added the stage: needs investigating Someone from Cypress needs to look at this label Jul 6, 2020
@Tobbe
Copy link

Tobbe commented Jul 6, 2020

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

@threehams
Copy link
Author

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.

@crfrolik
Copy link

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?

@quantumsheep
Copy link

Same issue with 4.11.0.

@threehams threehams changed the title Sporadic "Cannot set property 'err' of undefined" error occurs in place of other errors during automatic test-reruns on file save. "Cannot set property 'err' of undefined" error occurs in place of other errors during automatic test-reruns on file save. Jul 22, 2020
@jennifer-shehane
Copy link
Member

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

@artem-3dhubs
Copy link

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"

@threehams
Copy link
Author

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

@montogeek
Copy link

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

@kuceb
Copy link
Contributor

kuceb commented Aug 4, 2020

I'm working on this. We might have already fixed as part of #8113 (unfortunately didn't make it into last release), and I'm working on getting a reproducible test case to verify

@cypress-bot cypress-bot bot added stage: work in progress and removed stage: needs investigating Someone from Cypress needs to look at this labels Aug 4, 2020
@cypress-io cypress-io deleted a comment from sync-by-unito bot Aug 4, 2020
@kuceb
Copy link
Contributor

kuceb commented Aug 4, 2020

confirmed the work for this is done in #8113

Scheduled to release in version 4.12.1

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Aug 5, 2020

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.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Aug 5, 2020
@jennifer-shehane
Copy link
Member

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.