Skip to content

fix: prevent Cypress from crashing when getting machine-id fails#22119

Merged
tgriesser merged 2 commits intocypress-io:developfrom
Swaana:issue-22110
Jun 6, 2022
Merged

fix: prevent Cypress from crashing when getting machine-id fails#22119
tgriesser merged 2 commits intocypress-io:developfrom
Swaana:issue-22110

Conversation

@Swaana
Copy link
Copy Markdown
Contributor

@Swaana Swaana commented Jun 6, 2022

User facing changelog

The GUI will continue to run if getting machine-id fails.

Additional details

The underlying npm package node-machine-id requires admin rights on Windows to get the machine id. This is causing the Cypress GUI to crash for Windows users that do not have administrator rights. The fix will allow for the failure as the ID is optional.

Steps to test

To test this it requires a Windows machine and a non-admin user. Perhaps also an extra setting to prevent the user from running %windir%\System32\REG.exe. Running Cypress without this change will cause the application to crash right after selecting the type of test to perform, and after the change the application will run as normal.

How has the user experience changed?

The GUI will continue to run if getting machine-id fails.

PR Tasks

  • Have tests been added/updated?
  • Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • [na] Has a PR for user-facing changes been opened in cypress-documentation?
  • [na] Have API changes been updated in the type definitions?

@Swaana Swaana requested a review from tgriesser as a code owner June 6, 2022 10:25
@cypress-bot
Copy link
Copy Markdown
Contributor

cypress-bot Bot commented Jun 6, 2022

Thanks for taking the time to open a PR!

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jun 6, 2022

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

@flotwig flotwig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Swaana I was unable to reproduce this bug, even with a non-admin user account and the "Prevent access to registry editing tools" policy, but your changes make sense to me and look like they would catch the error, so I'll approve.

@tgriesser is this another example of something that we could catch higher up in the data-context in GUI mode?

@tgriesser
Copy link
Copy Markdown
Member

@tgriesser is this another example of something that we could catch higher up in the data-context in GUI mode?

@flotwig This is another example of an unhandledRejection which we are currently treating as a fatal error in all cases. I think the adjustment would be to send error reports on these / log to the console but not crash open mode on them.

const globalExceptionHandler = async (err) => {
await require('./errors').logException(err)
process.exit(1)
}
process.removeAllListeners('unhandledRejection')
process.once('unhandledRejection', globalExceptionHandler)

@flotwig
Copy link
Copy Markdown
Contributor

flotwig commented Jun 6, 2022

@tgriesser we should exit on unhandledRejections always since it means the program is in an undefined state. I'm not super familiar with this area, do you know off the top of your head how this is being called? If it's in response to a GraphQL query, etc.

@tgriesser
Copy link
Copy Markdown
Member

It's because we're not await'ing the promise:

try {
  return nmi.machineId()
} catch (error) {
  return undefined
}

vs

try {
  return await nmi.machineId()
} catch (error) {
  return undefined
}

the former will lead to an unhandledRejection if it throws and isn't caught higher up in the chain - which it isn't because it's not in the try block in getLatestVersion, same problem as #22099.

Has nothing to do with GraphQL, it's more to do with the fact that we're now using async/await rather than promise chains everywhere and not always ensuring there's proper awaiting. I think it's something we can introduce linting for but IIRC there were problems with false positives & negatives.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cypress >= 10 GUI crashes on Windows as non-admin user when registry editing is disabled

5 participants