Path: blob/main/scripts/chat-simulation/fixtures/_chatperf_errors.ts
13383 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45// perf-benchmark-marker67/**8* Fixture for chat-simulation benchmarks.9* Simplified from src/vs/base/common/errors.ts for stable perf testing.10*/1112export interface ErrorListenerCallback {13(error: any): void;14}1516export interface ErrorListenerUnbind {17(): void;18}1920const _errorListeners: ErrorListenerCallback[] = [];2122export function setUnexpectedErrorHandler(handler: ErrorListenerCallback): void {23_errorListeners.length = 0;24_errorListeners.push(handler);25}2627export function onUnexpectedError(e: any): void {28if (!isCancellationError(e)) {29for (const listener of _errorListeners) {30try { listener(e); } catch { }31}32}33}3435export function onUnexpectedExternalError(e: any): void {36if (!isCancellationError(e)) {37for (const listener of _errorListeners) {38try { listener(e); } catch { }39}40}41}4243export function transformErrorForSerialization(error: any): any {44if (error instanceof Error) {45const { name, message, stack } = error;46return { $isError: true, name, message, stack };47}48return error;49}5051const canceledName = 'Canceled';5253export function isCancellationError(error: any): boolean {54if (error instanceof CancellationError) { return true; }55return error instanceof Error && error.name === canceledName && error.message === canceledName;56}5758export class CancellationError extends Error {59constructor() {60super(canceledName);61this.name = this.message;62}63}6465export class NotSupportedError extends Error {66constructor(message?: string) {67super(message || 'NotSupported');68}69}7071export class NotImplementedError extends Error {72constructor(message?: string) {73super(message || 'NotImplemented');74}75}7677export class IllegalArgumentError extends Error {78constructor(message?: string) {79super(message || 'Illegal argument');80}81}8283export class BugIndicatingError extends Error {84constructor(message?: string) {85super(message || 'Bug Indicating Error');86}87}888990