Skip to content

Conversation

@felixfbecker
Copy link

@felixfbecker felixfbecker commented Feb 23, 2018

Closes #2037

@googlebot
Copy link

Thanks for your pull request. t looks like this may be your first contribution to a Google open source project (if not, look below for help). 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 (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers
  • Your company has a Point of Contact who decides which employees are authorized to participate. Ask your POC to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • The email used to register you as an authorized contributor must be the email used for the Git commit. Check your existing CLA data and verify that your email is set on your git commits.
  • The email used to register you as an authorized contributor must also be attached to your GitHub account.

@felixfbecker
Copy link
Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

this._polling = polling;
this._timeout = timeout;
this._predicateBody = helper.isString(predicateBody) ? 'return ' + predicateBody : 'return (' + predicateBody + ')(...args)';
this._title = title;
Copy link
Contributor

Choose a reason for hiding this comment

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

there's no need to save the title

Copy link
Author

Choose a reason for hiding this comment

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

There is also no need to save this._timeout, but it's helpful when using a debugger to see what the WaitTask does

Copy link
Contributor

Choose a reason for hiding this comment

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

this._timeout is used in rerun() method.

but it's helpful when using a debugger to see what the WaitTask does

I don't think it's a big of a deal: it's easy to save title once the debugging need occurs.

/**
* @param {!Frame} frame
* @param {Function|string} predicateBody
* @param {string} [title] what is being waited for (used in timeout error message)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: drop the comment and square braces around title

 * @param {string} title

Copy link
Author

Choose a reason for hiding this comment

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

The square brackets mean it's optional

Copy link
Contributor

Choose a reason for hiding this comment

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

Optional parameters are marked with = sign, e.g.:

 * @param {string=} title

However, I don't think it should be optional.

Copy link
Author

@felixfbecker felixfbecker Feb 23, 2018

Choose a reason for hiding this comment

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

I was looking at https://esdoc.org/manual/tags.html#optional-and-default

/**
 * @param {number} [param] - this is optional param.
 */
function myFunc(param){...}

/**
 * @param {number} [param=10] - this is default param.
 */
function myFunc(param){...}

Copy link
Contributor

Choose a reason for hiding this comment

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

We use closure annotations, there's a link to the manual in CONTRIBUTING.md

Check out optionals in closure annotations: https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#optional-parameter-in-a-param-annotation

const timeout = helper.isNumber(options.timeout) ? options.timeout : 30000;
const polling = options.polling || 'raf';
return new WaitTask(this, pageFunction, polling, timeout, ...args).promise;
return new WaitTask(this, pageFunction, options.title || 'function', polling, timeout, ...args).promise;
Copy link
Contributor

Choose a reason for hiding this comment

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

let's not add options.title; this will be an outlier in our api. Just passing in "function", or maybe stringified function body is enough.

Copy link
Author

Choose a reason for hiding this comment

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

Then the core use case would not be solved, which was waitForSelector, which calls into waitForFunction internally.

An alternative approach would be to catch every error and prepend the error message. Would you prefer that?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. I'd prefer copying the three lines of waitForFunction in __waitForSelectorOrXPath method.

// Since page navigation requires us to re-install the pageScript, we should track
// timeout on our end.
this._timeoutTimer = setTimeout(() => this.terminate(new Error(`waiting failed: timeout ${timeout}ms exceeded`)), timeout);
this._timeoutTimer = setTimeout(() => this.terminate(new Error(`waiting ${title ? 'for ' + title : ''} failed: timeout ${timeout}ms exceeded`)), timeout);
Copy link
Contributor

Choose a reason for hiding this comment

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

i'd expect title to be always present, so no need for ternary operator

@aslushnikov
Copy link
Contributor

@felixfbecker thanks for working on this; it should help a lot to debug pptr script failures.

@aslushnikov
Copy link
Contributor

@felixfbecker Are still interested in landing this?

@felixfbecker
Copy link
Author

Yes, just didn't find the time to update it yet.

@yanivefraim
Copy link
Contributor

@felixfbecker - will be happy to help here, if you don’t have time..
@aslushnikov

@aslushnikov
Copy link
Contributor

@yanivefraim please do! I'd love to have this.

@yanivefraim
Copy link
Contributor

yanivefraim commented Mar 29, 2018

@yanivefraim please do! I'd love to have this.

@felixfbecker - is it ok if I will start a new PR?

@aslushnikov
Copy link
Contributor

Closing in favor of #2292

@felixfbecker felixfbecker deleted the timeout-error-message branch April 2, 2018 20:53
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.

4 participants