Skip to content

Improve Uncaught Errors #1761

Closed
Closed
@kuceb

Description

@kuceb
Contributor

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

Activity

changed the title [-]Improve Errors[/-] [+]Improve Uncaught Errors[/+] on May 23, 2018
mackelito

mackelito commented on Feb 13, 2019

@mackelito

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

benjie commented on Aug 21, 2019

@benjie

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.

added
stage: needs reviewThe PR code is done & tested, needs review
and removed on May 4, 2020
cypress-bot

cypress-bot commented on May 6, 2020

@cypress-bot
Contributor

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

cypress-bot commented on May 20, 2020

@cypress-bot
Contributor

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.

locked as resolved and limited conversation to collaborators on May 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @benjie@mackelito@jennifer-shehane@kuceb

      Issue actions

        Improve Uncaught Errors · Issue #1761 · cypress-io/cypress