Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/scripts/chat-simulation/fixtures/_chatperf_errors.ts
13383 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
// perf-benchmark-marker
7
8
/**
9
* Fixture for chat-simulation benchmarks.
10
* Simplified from src/vs/base/common/errors.ts for stable perf testing.
11
*/
12
13
export interface ErrorListenerCallback {
14
(error: any): void;
15
}
16
17
export interface ErrorListenerUnbind {
18
(): void;
19
}
20
21
const _errorListeners: ErrorListenerCallback[] = [];
22
23
export function setUnexpectedErrorHandler(handler: ErrorListenerCallback): void {
24
_errorListeners.length = 0;
25
_errorListeners.push(handler);
26
}
27
28
export function onUnexpectedError(e: any): void {
29
if (!isCancellationError(e)) {
30
for (const listener of _errorListeners) {
31
try { listener(e); } catch { }
32
}
33
}
34
}
35
36
export function onUnexpectedExternalError(e: any): void {
37
if (!isCancellationError(e)) {
38
for (const listener of _errorListeners) {
39
try { listener(e); } catch { }
40
}
41
}
42
}
43
44
export function transformErrorForSerialization(error: any): any {
45
if (error instanceof Error) {
46
const { name, message, stack } = error;
47
return { $isError: true, name, message, stack };
48
}
49
return error;
50
}
51
52
const canceledName = 'Canceled';
53
54
export function isCancellationError(error: any): boolean {
55
if (error instanceof CancellationError) { return true; }
56
return error instanceof Error && error.name === canceledName && error.message === canceledName;
57
}
58
59
export class CancellationError extends Error {
60
constructor() {
61
super(canceledName);
62
this.name = this.message;
63
}
64
}
65
66
export class NotSupportedError extends Error {
67
constructor(message?: string) {
68
super(message || 'NotSupported');
69
}
70
}
71
72
export class NotImplementedError extends Error {
73
constructor(message?: string) {
74
super(message || 'NotImplemented');
75
}
76
}
77
78
export class IllegalArgumentError extends Error {
79
constructor(message?: string) {
80
super(message || 'Illegal argument');
81
}
82
}
83
84
export class BugIndicatingError extends Error {
85
constructor(message?: string) {
86
super(message || 'Bug Indicating Error');
87
}
88
}
89
90