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

Better string representation of errors #2712

Merged
merged 1 commit into from
Nov 27, 2017
Merged

Better string representation of errors #2712

merged 1 commit into from
Nov 27, 2017

Conversation

macjohnny
Copy link
Contributor

@macjohnny macjohnny commented May 17, 2017

Resolves #2711

Before:

Chrome 59.0.3071 (Mac OS X 10.12.3) ERROR
 {
      "originalErr": {},
      "__zone_symbol__currentTask": {
        "type": "microTask",
        "state": "notScheduled",
        "source": "Promise.then",
        "zone": "<root>",
        "cancelFn": null,
        "runCount": 0
      }
  }
Chrome 59.0.3071 (Mac OS X 10.12.3): Executed 0 of 0 ERROR (1.348 secs / 0 secs)

After:

Chrome 59.0.3071 (Mac OS X 10.12.3) ERROR
 {
    "message": {
      "originalErr": {},
      "__zone_symbol__currentTask": {
        "type": "microTask",
        "state": "notScheduled",
        "source": "Promise.then",
        "zone": "<root>",
        "cancelFn": null,
        "runCount": 0
      }
    },
    "str": [
      "Error: (SystemJS) Object prototype may only be an Object or null: undefined",
      "    TypeError: Object prototype may only be an Object or null: undefined",
      "        at setPrototypeOf (<anonymous>)",
      "        at __extends$1 (dist/bundles/my-bundle.umd.js:2258:9)",
    ]
  }
Chrome 59.0.3071 (Mac OS X 10.12.3): Executed 0 of 0 ERROR (1.348 secs / 0 secs)

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@macjohnny
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

client/karma.js Outdated

// create an object with the string representation of the message to ensure all its content is properly
// transferred to the console log
message = {message: message, str: message.toString().replace(/\t/g, " ").split("\n")}
Copy link
Member

Choose a reason for hiding this comment

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

The replace and split parts should probably be removed.

Also, this line changes the message variable's type from string to an object - this probably means that tests have to be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the replace and split parts are for nicer output display in the console, since the object is converted to json.
With the split and replace, you get

"str": [
      "Error: (SystemJS) Object prototype may only be an Object or null: undefined",
      "    TypeError: Object prototype may only be an Object or null: undefined",
      "        at setPrototypeOf (<anonymous>)",
      "        at __extends$1 (dist/bundles/my-bundle.umd.js:2258:9)",
    ]

instead of

"str": "Error: (SystemJS) Object prototype may only be an Object or null: undefined\n\tTypeError: Object prototype may only be an Object or null: undefined\n\tat setPrototypeOf (<anonymous>)\n\tat __extends$1 (dist/bundles/my-bundle.umd.js:2258:9)",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the variable type is not changed, the message already is an object that will later on be converted to a string with JSON.stringify()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the message might be a string or an object

@macjohnny
Copy link
Contributor Author

@wesleycho could you have a look at this again? this patch really helped me a lot when investigating preliminary import / systemjs issues that prevented the tests from being run and log a useful message.

@macjohnny
Copy link
Contributor Author

@wesleycho could you please have a look at this again?

@larsduelfer
Copy link

I would also highly appreciate if this change is going to be integrated.

Copy link
Collaborator

@EzraBrooks EzraBrooks left a comment

Choose a reason for hiding this comment

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

I agree with @wesleycho, I’d say the error should remain a string. Formatting of the message itself should be left to the client console or to formatting methods, instead of having the message be preformatted when attached to the object.

@macjohnny
Copy link
Contributor Author

macjohnny commented Nov 27, 2017

@EzraBrooks @wesleycho I can understand the formatting should not be done here. but since the message can be an object (which is the reason for this PR), it should be ok to transform it to a different object as I suggest in this PR. would you accept this PR if I removed the .replace(/\t/g, " ").split("\n") part?

@EzraBrooks
Copy link
Collaborator

Thanks, I’ll approve it once the CI checks complete.

@macjohnny
Copy link
Contributor Author

@EzraBrooks it seems there is a problem with the travis ci build retrieving some commit message. however, all other tests pass. could you please have a look at it?

@EzraBrooks
Copy link
Collaborator

Please squash your commits into one that follows Karma’s naming conventions - Travis is failing on commit message validation.

@EzraBrooks
Copy link
Collaborator

Sorry, to clarify.. the commit messages all have a leading type on them. In this case, I would recommend feat: better string representation of errors.

@macjohnny
Copy link
Contributor Author

@EzraBrooks done, waiting for the CI to complete

@EzraBrooks
Copy link
Collaborator

Looks like ESLint has a few style complaints.

@macjohnny
Copy link
Contributor Author

@EzraBrooks I updated the PR, hope it is fine now

Copy link
Collaborator

@EzraBrooks EzraBrooks left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@EzraBrooks EzraBrooks merged commit b53929a into karma-runner:master Nov 27, 2017
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.

5 participants