(props: Partial<TelemetryErrorProperties>, error: Error)
| 9 | |
| 10 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 11 | export async function populateTelemetryWithErrorInfo(props: Partial<TelemetryErrorProperties>, error: Error) { |
| 12 | props.failed = true; |
| 13 | // Don't blow away what we already have. |
| 14 | props.failureCategory = props.failureCategory || getErrorCategory(error); |
| 15 | |
| 16 | // Detect fetch errors by shape instead of using instanceof |
| 17 | // - Native FetchError (node-fetch or some runtimes): error.name === 'FetchError' |
| 18 | // - Browser fetch failures: error.name === 'TypeError' && message matches 'failed to fetch' |
| 19 | // - Global FetchError support: check if globalThis has FetchError |
| 20 | const globalFetchError = (globalThis as typeof globalThis & { FetchError?: ErrorConstructor }).FetchError; |
| 21 | const isFetchError = |
| 22 | error?.name === 'FetchError' || |
| 23 | (error?.name === 'TypeError' && /failed to fetch/i.test(String(error.message))) || |
| 24 | (typeof globalFetchError !== 'undefined' && error instanceof globalFetchError); |
| 25 | |
| 26 | if (props.failureCategory === 'unknown' && isFetchError) { |
| 27 | props.failureCategory = 'fetcherror'; |
| 28 | } |
| 29 | |
| 30 | props.stackTrace = serializeStackTrace(error); |
| 31 | if (typeof error === 'string') { |
| 32 | // Helps us determine that we are rejecting with errors in some places, in which case we aren't getting meaningful errors/data. |
| 33 | props.failureSubCategory = 'errorisstring'; |
| 34 | } |
| 35 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 36 | const stdErr = (error as BaseError).stdErr ? (error as BaseError).stdErr : error.stack || ''; |
| 37 | if (!stdErr) { |
| 38 | return; |
| 39 | } |
| 40 | props.failureSubCategory = props.failureSubCategory || getErrorTags(stdErr); |
| 41 | const info = getLastFrameFromPythonTraceback(stdErr); |
| 42 | if (!info) { |
| 43 | return; |
| 44 | } |
| 45 | [props.pythonErrorFile, props.pythonErrorFolder, props.pythonErrorPackage] = await Promise.all([ |
| 46 | Promise.resolve(props.pythonErrorFile || getTelemetrySafeHashedString(info.fileName)), |
| 47 | Promise.resolve(props.pythonErrorFolder || getTelemetrySafeHashedString(info.folderName)), |
| 48 | Promise.resolve(props.pythonErrorPackage || getTelemetrySafeHashedString(info.packageName)) |
| 49 | ]); |
| 50 | } |
| 51 | |
| 52 | export function parseStack(ex: Error) { |
| 53 | // Work around bug in stackTrace when ex has an array already |
no test coverage detected