( message, filename, line, col, error, hasNonAmpJs )
| 488 | * visibleForTesting |
| 489 | */ |
| 490 | export function getErrorReportData( |
| 491 | message, |
| 492 | filename, |
| 493 | line, |
| 494 | col, |
| 495 | error, |
| 496 | hasNonAmpJs |
| 497 | ) { |
| 498 | message = buildErrorMessage_(message, error); |
| 499 | // An "expected" error is still an error, i.e. some features are disabled |
| 500 | // or not functioning fully because of it. However, it's an expected |
| 501 | // error. E.g. as is the case with some browser API missing (storage). |
| 502 | // Thus, the error can be classified differently by log aggregators. |
| 503 | // The main goal is to monitor that an "expected" error doesn't deteriorate |
| 504 | // over time. It's impossible to completely eliminate it. |
| 505 | let expected = !!(error && error.expected); |
| 506 | if (/_reported_/.test(message)) { |
| 507 | return; |
| 508 | } |
| 509 | if (message == CANCELLED) { |
| 510 | return; |
| 511 | } |
| 512 | |
| 513 | const detachedWindow = !(self && self.window); |
| 514 | const throttleBase = Math.random(); |
| 515 | |
| 516 | // We throttle load errors and generic "Script error." errors |
| 517 | // that have no information and thus cannot be acted upon. |
| 518 | if ( |
| 519 | isLoadErrorMessage(message) || |
| 520 | // See https://github.com/ampproject/amphtml/issues/7353 |
| 521 | // for context. |
| 522 | message == 'Script error.' || |
| 523 | // Window has become detached, really anything can happen |
| 524 | // at this point. |
| 525 | detachedWindow |
| 526 | ) { |
| 527 | expected = true; |
| 528 | |
| 529 | if (throttleBase < NON_ACTIONABLE_ERROR_THROTTLE_THRESHOLD) { |
| 530 | return; |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | const isUserError = isUserErrorMessage(message); |
| 535 | |
| 536 | // Only report a subset of user errors. |
| 537 | if (isUserError && throttleBase < USER_ERROR_THROTTLE_THRESHOLD) { |
| 538 | return; |
| 539 | } |
| 540 | |
| 541 | // This is the App Engine app in |
| 542 | // https://github.com/ampproject/error-tracker |
| 543 | // It stores error reports via https://cloud.google.com/error-reporting/ |
| 544 | // for analyzing production issues. |
| 545 | const data = /** @type {!JsonObject} */ (Object.create(null)); |
| 546 | data['v'] = getMode().rtvVersion; |
| 547 | data['noAmp'] = hasNonAmpJs ? '1' : '0'; |
no test coverage detected