-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Add title to WaitTask for debugging purposes #2084
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
Conversation
|
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. What to do if you already signed the CLAIndividual signers
Corporate signers
|
|
I signed it! |
|
CLAs look good, thanks! |
27a96e8 to
6625b3c
Compare
6625b3c to
f5b4d03
Compare
| this._polling = polling; | ||
| this._timeout = timeout; | ||
| this._predicateBody = helper.isString(predicateBody) ? 'return ' + predicateBody : 'return (' + predicateBody + ')(...args)'; | ||
| this._title = title; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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} titleThere was a problem hiding this comment.
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
There was a problem hiding this comment.
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=} titleHowever, I don't think it should be optional.
There was a problem hiding this comment.
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){...}
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
|
@felixfbecker thanks for working on this; it should help a lot to debug pptr script failures. |
|
@felixfbecker Are still interested in landing this? |
|
Yes, just didn't find the time to update it yet. |
|
@felixfbecker - will be happy to help here, if you don’t have time.. |
|
@yanivefraim please do! I'd love to have this. |
@felixfbecker - is it ok if I will start a new PR? |
|
Closing in favor of #2292 |
Closes #2037