-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Exclude errors generated from A4A iframe #10562
Conversation
This is just initial skeleton, I'm hoping to see whether the if else logic in user() is good. The next thing to do is to get ampdoc here (right now there's no win object) @lannka |
src/log.js
Outdated
* @return {!Log} | ||
*/ | ||
export function user() { | ||
export function user(opt_element) { | ||
if (logs.user) { |
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 should now cache 2 instances of user logger.
logs.user
logs.userForEmbed
logic will be like:
if (isFromEmbed(opt_element) {
if (!logs.userForEmbed) {
logs.userForEmbed = ...
}
return logs.userForEmbed;
} else {
if (!logs.user) {
logs.user = ...
}
return logs.user;
}
src/log.js
Outdated
/** | ||
* @return {boolean} Whether this message was a iframe embed error. | ||
*/ | ||
function isErrorEmbed(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.
isUserErrorEmbed
src/log.js
Outdated
* | ||
* @const {string} | ||
*/ | ||
export const EMBED = '\u200B\u200B\u200B\u200B'; |
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.
USER_ERROR_EMBED_SENTINEL
src/log.js
Outdated
if (logs.userForEmbed) { | ||
return logs.userForEmbed; | ||
} | ||
logs.userForEmbed = new logConstructor(self, mode => { |
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.
seems duplicated logic, can we consolidate with getUserLogger?
src/error.js
Outdated
if (error && isUserErrorMessage(error.message) && !!win) { | ||
reportErrorToAnalytics(/** @type {!Error} */(error), win); | ||
if (error && !!win) { | ||
if (isUserErrorMessage(error.message) && !error.embed) { |
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.
seems no nested if needed
test/functional/test-log.js
Outdated
}); | ||
|
||
it('should return logger for user-error', () => { | ||
expect(user().suffix_).to.equal(USER_ERROR_SENTINEL); |
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.
you can use
const error = user().createError();
expect(isUserErrorEmbed(error.message)).to.be.false;
also add test to make sure you not not creating extra identical logger
expect(user()).to.equal(user(element1));
expect(user()).to.equal(user(element2));
@@ -18,8 +18,8 @@ | |||
# Historically, amp-ad/amp-embed javascript were embedded into the main | |||
# runtime (v0.js), so there are many pages that do not include the amp-ad | |||
# extension. We want to warn for these. | |||
# AMP-EMBED requires the amp-ad extension, not amp-embed. | |||
# Including the amp-ad extension, but not an AMP-AD/AMP-EMBED tag should only | |||
# AMP-USER_ERROR_EMBED_SENTINEL requires the amp-ad extension, not amp-embed. |
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.
<amp-embed>
stays <amp-embed>
, please revert
src/error.js
Outdated
@@ -97,7 +97,7 @@ let detectedJsEngine; | |||
*/ | |||
export function reportErrorForWin(win, error, opt_associatedElement) { | |||
reportError(error, opt_associatedElement); | |||
if (error && isUserErrorMessage(error.message) && !!win) { | |||
if (error && !!win && isUserErrorMessage(error.message) && !error.embed) { |
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.
should we use isUserErrorEmbed(error.message)
here? Same reason to why we don't have error.isUserError
.
src/log.js
Outdated
@@ -210,6 +229,7 @@ export class Log { | |||
const error = this.error_.apply(this, arguments); | |||
if (error) { | |||
error.name = tag || error.name; | |||
error.embed = isUserErrorEmbed(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.
I thought only error.message
will survive, should we still use error.embed
?
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.
yeah i just realized, seems like error.embed is not needed anymore
@@ -341,6 +341,7 @@ var forbiddenTerms = { | |||
'extensions/amp-access/0.1/amp-access.js', | |||
'extensions/amp-experiment/0.1/variant.js', | |||
'extensions/amp-user-notification/0.1/amp-user-notification.js', | |||
'dist.3p/current/integration.js', |
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.
what's this for?
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.
@zhouyx When i run presubmit it shows that i'm using cid, so Hongfei suggested to whitelist it.
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.
sorry if there's mis-understanding, but I don't see it cid used in your change. did you try make a new build and run presubmit again?
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.
LGTM, some minor comments
src/log.js
Outdated
* @return {boolean} Whether this message was a user error. | ||
*/ | ||
export function isUserErrorMessage(message) { | ||
return message.indexOf(USER_ERROR_SENTINEL) >= 0; | ||
} | ||
|
||
/** | ||
* @return {boolean} Whether this message was a iframe embed error. |
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.
Whether this message was a a user error from an iframe embed
src/log.js
Outdated
* @return {!Log} | ||
*/ | ||
export function user() { | ||
export function user(opt_element) { | ||
let logger; |
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.
seems this local var is not needed
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.
@lannka i think it is because I'd need to assign different value to this var and also use it at the last return call. Lmk what you think!
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.
why don't you just assign to logs.user
?
test/functional/test-log.js
Outdated
it('should return logger for user-error', () => { | ||
const error = user().createError(); | ||
expect(isUserErrorEmbed(error.message)).to.be.false; | ||
expect(user(this.element).suffix_).to.equal(USER_ERROR_SENTINEL); |
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.
avoid checking member field
expect(isUserError(error.message)).to.be.true;
test/functional/test-log.js
Outdated
it('should return logger for embed-error', () => { | ||
element = document.createElement('embed'); | ||
iframe.contentWindow.document.body.appendChild(element); | ||
expect(user(element).suffix_).to.equal(USER_ERROR_EMBED_SENTINEL); |
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.
same here
test/functional/test-log.js
Outdated
expect(user(element).suffix_).to.equal(USER_ERROR_EMBED_SENTINEL); | ||
}); | ||
|
||
it('should not create extra identical logs', () => { |
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.
loggers
iframe.contentWindow.document.body.appendChild(element1); | ||
iframe.contentWindow.document.body.appendChild(element2); | ||
expect(user()).to.equal(user(this.element)); | ||
expect(user(element1)).to.equal(user(element2)); |
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.
add one more check:
expect(user()).to.not.equal(user(element1));
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.
@lannka i made all requested change. Thanks!
src/log.js
Outdated
if (logs.user) { | ||
logs.user = logs.user; |
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.
why this?
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.
LGTM with one question.
builtins/amp-img.js
Outdated
user().error('AMP-IMG', 'Setting role=img on amp-img elements breaks ' + | ||
'screen readers please just set alt or ARIA attributes, they will ' + | ||
'be correctly propagated for the underlying <img> element.'); | ||
user(this.element).error('AMP-IMG', |
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.
Question: Do we plan to migrate to the new user(opt_element)
in this PR? If so why we only make the change to amp-img.js
. I would suggest migrate to new format in separate PR.
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.
@zhouyx I need that change to amp-img.js to do the test, but the whole migration to use(opt_element) would be in a separate PR. Is that ok?
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.
Talked offline. Please revert. and I'll approve and merge the PR.
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.
@zhouyx reverted!
src/log.js
Outdated
*/ | ||
export function isFromEmbed(win, opt_element) { | ||
if (!!opt_element) { | ||
return opt_element.ownerDocument.defaultView != win; |
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.
nitpick: logically cleaner to flip the if
LGTM @zhouyx pls help merge once you have done the review. |
User error Reporting:
Filter out errors generated from A4A iframe embed