| import type { TurbopackInternalErrorOpts } from '../../../build/swc/generated-native' |
| import { eventErrorThrown } from '../../../telemetry/events' |
| import { traceGlobals } from '../../../trace/shared' |
|
|
| |
| |
| |
| |
| |
| |
| export class TurbopackInternalError extends Error { |
| name = 'TurbopackInternalError' |
| location: string | undefined |
|
|
| |
| __NEXT_ERROR_CODE = 'TurbopackInternalError' |
|
|
| constructor({ message, anonymizedLocation }: TurbopackInternalErrorOpts) { |
| super(message) |
| this.location = anonymizedLocation |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| export function throwTurbopackInternalError( |
| conversionError: Error | null, |
| opts: TurbopackInternalErrorOpts |
| ): never { |
| if (conversionError != null) { |
| |
| throw new Error( |
| 'NAPI type conversion error in throwTurbopackInternalError', |
| { |
| cause: conversionError, |
| } |
| ) |
| } |
| const err = new TurbopackInternalError(opts) |
| const telemetry = traceGlobals.get('telemetry') |
| if (telemetry) { |
| telemetry.record(eventErrorThrown(err, opts.anonymizedLocation)) |
| } else { |
| console.error('Expected `telemetry` to be set in globals') |
| } |
| throw err |
| } |
|
|