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

Check for Browsertime errors in run(). #300

Merged
merged 2 commits into from Oct 7, 2018
Merged

Check for Browsertime errors in run(). #300

merged 2 commits into from Oct 7, 2018

Conversation

jadonn
Copy link
Contributor

@jadonn jadonn commented Oct 1, 2018

When Coach is run from another script and Browsertime cannot access
Selenium Grid, run() fails with TypeError: coach is undefined from
result.browserScripts[0].coach. This commit adds rough error checking for
Browsertime errors and returns a new Error object
so the running script can handle the error.

Your checklist for this pull request

Please review the guidelines for contributing to this repository.

  • [ X ] Check that your change/fix has corresponding unit tests
    I do not believe the change requires any changes to unit tests.
  • [ X ] Verify that the test works by running npm test and test linting by npm run lint
    npm test and npm run lint run successfully with the change.
  • [ X ] Squash commits so it looks sane
    The change should be reasonably simple. There is only one commit.

Description

Please describe your pull request and tell us the fix #

When Browsertime's attempt to connect to Selenium fails or times out, webcoach.run() fails with the following error:

TypeError: Cannot read property 'coach' of undefined
at runBrowsertime.then.result (/path/to/project/coach-api/node_modules/webcoach/lib/index.js:118:50)
at
at process._tickCallback (internal/process/next_tick.js:188:7)

I added a rough check for Browsertime errors to enable me to catch when this kind of problem happens in the script that runs webcoach.run(). If the check is too rough or if there is a better way to catch this error in Coach or my application, I would be happy to give writing an error check another go. I would really like to be able to catch this error in my own application, and I certainly want to give it back if it would be helpful to others.

Thank you for helping the coach!

When Coach is run from another script and Browsertime cannot access
Selenium Grid, run() fails with TypeError: coach is undefined from
 result.browserScripts[0].coach. This commit adds rough error checking for
Browsertime errors and returns a new Error object
so the running script can handle the error.
@soulgalore
Copy link
Member

Hi @jadonn thanks for the fix! Let me merge this before next release!

@soulgalore
Copy link
Member

I need to think a little how we should handle it, I'm not 100% sure yet.

@jadonn
Copy link
Contributor Author

jadonn commented Oct 3, 2018

That is no problem! Thanks for the response. If there's a better way, I'm happy to work on this more and to learn how it could be better.

@soulgalore
Copy link
Member

Yeah what about just throw an error? That what happens right now if Browsertime has some problems or ... maybe need to check :)

@jadonn
Copy link
Contributor Author

jadonn commented Oct 4, 2018

Thanks for the feedback! Throwing does make more sense. I don't remember why I initially chose to return the error instead of throwing it. I submitted another commit that changes the return to throw. I really appreciate the work you've done with the Coach and Sitespeed.io! It's a great tool, and I'm excited for the opportunity to give a little bit back to it.

result.errors[0].length !== 0
) {
const browsertimeError = new Error(result.errors);
browsertimeError.name = 'BROWSERTIMEERROR';
Copy link
Member

Choose a reason for hiding this comment

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

Can you just rename this to BrowsertimeError instead, that's how we try to name errors.

Copy link
Member

@soulgalore soulgalore left a comment

Choose a reason for hiding this comment

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

Just fix the name and then I merge and release it. Thanks for taking the time to make the PR!

@soulgalore
Copy link
Member

Let me fix that so we can move on with the release :) Thank you @jadonn !

@soulgalore soulgalore merged commit 5abb5ee into sitespeedio:master Oct 7, 2018
@jadonn
Copy link
Contributor Author

jadonn commented Oct 8, 2018

Thank you so much @soulgalore ! I apologize I was not able to make the correction in good time

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.

None yet

2 participants