()
| 1355 | }; |
| 1356 | |
| 1357 | const installRuntimeErrorDiagnostics = () => { |
| 1358 | runtimeErrorListener = (event: ErrorEvent) => { |
| 1359 | const normalized = normalizeDiagnosticMessage(event.error ?? event.message).slice( |
| 1360 | 0, |
| 1361 | MAX_DIAGNOSTIC_MESSAGE_LENGTH, |
| 1362 | ); |
| 1363 | if (!normalized) { |
| 1364 | return; |
| 1365 | } |
| 1366 | const classified = classifyRuntimeScriptFailure(normalized); |
| 1367 | postRuntimeMessage({ |
| 1368 | source: "hf-preview", |
| 1369 | type: "diagnostic", |
| 1370 | code: classified.code, |
| 1371 | details: { |
| 1372 | category: classified.category, |
| 1373 | message: normalized, |
| 1374 | filename: event.filename || null, |
| 1375 | line: Number.isFinite(event.lineno) ? event.lineno : null, |
| 1376 | column: Number.isFinite(event.colno) ? event.colno : null, |
| 1377 | }, |
| 1378 | }); |
| 1379 | }; |
| 1380 | runtimeUnhandledRejectionListener = (event: PromiseRejectionEvent) => { |
| 1381 | const normalized = normalizeDiagnosticMessage(event.reason).slice( |
| 1382 | 0, |
| 1383 | MAX_DIAGNOSTIC_MESSAGE_LENGTH, |
| 1384 | ); |
| 1385 | if (!normalized) { |
| 1386 | return; |
| 1387 | } |
| 1388 | const classified = classifyRuntimeScriptFailure(normalized); |
| 1389 | postRuntimeMessage({ |
| 1390 | source: "hf-preview", |
| 1391 | type: "diagnostic", |
| 1392 | code: `${classified.code}_unhandled_rejection`, |
| 1393 | details: { |
| 1394 | category: `${classified.category}-unhandled-rejection`, |
| 1395 | message: normalized, |
| 1396 | }, |
| 1397 | }); |
| 1398 | }; |
| 1399 | window.addEventListener("error", runtimeErrorListener); |
| 1400 | window.addEventListener("unhandledrejection", runtimeUnhandledRejectionListener); |
| 1401 | }; |
| 1402 | |
| 1403 | const installAssetFailureDiagnostics = () => { |
| 1404 | const assetNodes = Array.from( |
no test coverage detected