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

Improve Uncaught Errors #1761

Closed
kuceb opened this issue May 23, 2018 · 4 comments · Fixed by #3930
Closed

Improve Uncaught Errors #1761

kuceb opened this issue May 23, 2018 · 4 comments · Fixed by #3930
Labels
topic: unhandled exceptions ⚠️ Issues involving unhandled or uncaught exception handling type: user experience Improvements needed for UX

Comments

@kuceb
Copy link
Contributor

kuceb commented May 23, 2018

on Uncaught Errors

  • if there is no err.stack, e.g syntax error, construct a better error
  • if there is a stack, cut out the cypress related lines

image

@kuceb kuceb changed the title Improve Errors Improve Uncaught Errors May 23, 2018
@jennifer-shehane jennifer-shehane added the type: user experience Improvements needed for UX label May 24, 2018
@mackelito
Copy link

mackelito commented Feb 13, 2019

Guess this is the same issue I have... causes tests to fail.

cypress_runner.js:65225 Uncaught TypeError: Cannot read property 'replace' of undefined
    at Object.appendErrMsg (cypress_runner.js:65225)
    at Object.createUncaughtException (cypress_runner.js:58408)
    at Object.onUncaughtException (cypress_runner.js:61281)
    at onError (cypress_runner.js:60780)

@jennifer-shehane jennifer-shehane added topic: unhandled exceptions ⚠️ Issues involving unhandled or uncaught exception handling stage: ready for work The issue is reproducible and in scope labels Feb 14, 2019
@benjie
Copy link

benjie commented Aug 21, 2019

I've just spent an hour getting to know Cypress intimately to track down the error I was getting. Spoiler: turns out the error was that electron doesn't currently support optional catch binding in try block:

try {
  ...
} catch {
  ...
}

The error I was receiving was:

Uncaught SyntaxError: Unexpected token {

This error originated from your application code, not from Cypress.

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

This doesn't contain anything useful for tracking down what is causing the error since there's {s everywhere.

After much exploration through the devtools I landed here:

cypress-error

This gave me the information I needed - the file, line number and column number of the syntax error. From then it only took a few more seconds to track down the actual syntax incompatibility.

The issue here seems to be that the source, lineno and colno information are being explicitly dropped here:

createUncaughtException = (type, args) ->
[msg, source, lineno, colno, err] = args

createErrFromMsg = ->
new Error $utils.errMessageByPath("uncaught.error", { msg, source, lineno })
## if we have the 5th argument it means we're in a super
## modern browser making this super simple to work with.
err ?= createErrFromMsg()

Because the error (argument 5) exists, the other details are discarded, which leads to a less-than-optimal debugging experience.

As far as I can tell, there's no way for me to extract these details with any cypress hooks, for example by the time it hits the uncaught:exception hook these details have been dropped (I think?).

Suggestion: add source, lineno and colno to the error object and ensure they're in the error message.

@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: ready for work The issue is reproducible and in scope labels May 4, 2020
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels May 6, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 6, 2020

The code for this is done in cypress-io/cypress#3930, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 20, 2020

Released in 4.6.0.

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

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: unhandled exceptions ⚠️ Issues involving unhandled or uncaught exception handling type: user experience Improvements needed for UX
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants