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

Use try catch to protect querySelector #12734

Merged
merged 3 commits into from Jan 10, 2018

Conversation

zhouyx
Copy link
Contributor

@zhouyx zhouyx commented Jan 9, 2018

closes #12563

try {
found = scopedQuerySelector(context, selector);
} catch (e) {
user().error(TAG, 'Invalid query selector :', selector, e);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We also throw user error when can't find target element. I figure invalid selector is somehow different from that error.
Let me know if two errors "invalid selector" + "element not found" are not wanted..

if (found && this.contains(found)) {
result = found;
}
return user().assertElement(
Copy link
Contributor

Choose a reason for hiding this comment

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

we can move this to be after the catch block to avoid doubling the error messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@zhouyx zhouyx merged commit ad9203e into ampproject:master Jan 10, 2018
@zhouyx zhouyx deleted the syntax-error-throw branch January 10, 2018 17:52
gzgogo pushed a commit to gzgogo/amphtml that referenced this pull request Jan 26, 2018
* use try catch to protect querySelector

* only send one error

* reorder
RanAbram pushed a commit to RanAbram/amphtml that referenced this pull request Mar 12, 2018
* use try catch to protect querySelector

* only send one error

* reorder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

amp-analytics: "Error: The string did not match the expected pattern."
3 participants