@opensumi/ide-utils 2.21.13 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/arrays.d.ts +3 -3
- package/lib/arrays.d.ts.map +1 -1
- package/lib/arrays.js.map +1 -1
- package/lib/async.d.ts +3 -3
- package/lib/async.d.ts.map +1 -1
- package/lib/buffer.js +4 -4
- package/lib/buffer.js.map +1 -1
- package/lib/character-classifier.js +3 -3
- package/lib/character-classifier.js.map +1 -1
- package/lib/decorators.d.ts +1 -1
- package/lib/decorators.d.ts.map +1 -1
- package/lib/encoding.d.ts +7 -1
- package/lib/encoding.d.ts.map +1 -1
- package/lib/encoding.js +15 -2
- package/lib/encoding.js.map +1 -1
- package/lib/errors.d.ts +2 -2
- package/lib/errors.d.ts.map +1 -1
- package/lib/event.d.ts +2 -2
- package/lib/event.d.ts.map +1 -1
- package/lib/filters.d.ts +3 -3
- package/lib/filters.d.ts.map +1 -1
- package/lib/filters.js +25 -25
- package/lib/filters.js.map +1 -1
- package/lib/glob.d.ts +2 -2
- package/lib/glob.d.ts.map +1 -1
- package/lib/glob.js +1 -1
- package/lib/glob.js.map +1 -1
- package/lib/hash.js +10 -10
- package/lib/hash.js.map +1 -1
- package/lib/iterator.d.ts +1 -1
- package/lib/iterator.d.ts.map +1 -1
- package/lib/linked-text.d.ts +1 -1
- package/lib/linked-text.d.ts.map +1 -1
- package/lib/linked-text.js.map +1 -1
- package/lib/map.js +17 -17
- package/lib/map.js.map +1 -1
- package/lib/objects.d.ts +1 -0
- package/lib/objects.d.ts.map +1 -1
- package/lib/objects.js +38 -1
- package/lib/objects.js.map +1 -1
- package/lib/os.d.ts +1 -8
- package/lib/os.d.ts.map +1 -1
- package/lib/os.js +4 -8
- package/lib/os.js.map +1 -1
- package/lib/path.d.ts +1 -1
- package/lib/path.d.ts.map +1 -1
- package/lib/path.js +29 -29
- package/lib/path.js.map +1 -1
- package/lib/platform.js +8 -8
- package/lib/platform.js.map +1 -1
- package/lib/process.d.ts.map +1 -1
- package/lib/process.js +28 -13
- package/lib/process.js.map +1 -1
- package/lib/progress.js +3 -3
- package/lib/progress.js.map +1 -1
- package/lib/strings.js +9 -9
- package/lib/strings.js.map +1 -1
- package/lib/types.d.ts +5 -1
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +8 -1
- package/lib/types.js.map +1 -1
- package/lib/uint.js +4 -4
- package/lib/uint.js.map +1 -1
- package/lib/uri.js +8 -8
- package/lib/uri.js.map +1 -1
- package/lib/uuid.d.ts +1 -1
- package/lib/uuid.d.ts.map +1 -1
- package/lib/uuid.js +3 -2
- package/lib/uuid.js.map +1 -1
- package/package.json +8 -6
- package/src/ansi.ts +10 -0
- package/src/argv.ts +57 -0
- package/src/arrays.ts +328 -0
- package/src/async.ts +580 -0
- package/src/buffer.ts +290 -0
- package/src/cache.ts +37 -0
- package/src/cancellation.ts +136 -0
- package/src/charCode.ts +425 -0
- package/src/character-classifier.ts +82 -0
- package/src/const/encoding.ts +242 -0
- package/src/const/index.ts +1 -0
- package/src/date.ts +36 -0
- package/src/decorators.ts +166 -0
- package/src/disposable.ts +377 -0
- package/src/encoding.ts +278 -0
- package/src/errors.ts +192 -0
- package/src/event.ts +1024 -0
- package/src/file-uri.ts +41 -0
- package/src/filters.ts +887 -0
- package/src/functional.ts +43 -0
- package/src/glob.ts +752 -0
- package/src/hash.ts +336 -0
- package/src/iconLabels.ts +149 -0
- package/src/index.ts +40 -0
- package/src/iterator.ts +36 -0
- package/src/lifecycle.ts +48 -0
- package/src/linked-list.ts +144 -0
- package/src/linked-text.ts +55 -0
- package/src/lru-map.ts +133 -0
- package/src/map.ts +934 -0
- package/src/marshalling.ts +62 -0
- package/src/objects.ts +145 -0
- package/src/os.ts +76 -0
- package/src/path.ts +1885 -0
- package/src/platform.ts +194 -0
- package/src/process.ts +43 -0
- package/src/progress.ts +83 -0
- package/src/promises.ts +23 -0
- package/src/sequence.ts +28 -0
- package/src/strings.ts +1002 -0
- package/src/types.ts +214 -0
- package/src/uint.ts +59 -0
- package/src/uri.ts +298 -0
- package/src/uuid.ts +6 -0
package/src/errors.ts
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
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
|
+
// Some code copied and modified from https://github.com/microsoft/vscode/blob/1.44.0/src/vs/base/common/errors.ts
|
|
6
|
+
|
|
7
|
+
export type ErrorListenerCallback = (error: any) => void;
|
|
8
|
+
|
|
9
|
+
export type ErrorListenerUnbind = () => void;
|
|
10
|
+
|
|
11
|
+
// Avoid circular dependency on EventEmitter by implementing a subset of the interface.
|
|
12
|
+
export class ErrorHandler {
|
|
13
|
+
private unexpectedErrorHandler: (e: any) => void;
|
|
14
|
+
private listeners: ErrorListenerCallback[];
|
|
15
|
+
|
|
16
|
+
constructor() {
|
|
17
|
+
this.listeners = [];
|
|
18
|
+
|
|
19
|
+
this.unexpectedErrorHandler = function (e: any) {
|
|
20
|
+
setTimeout(() => {
|
|
21
|
+
if (e.stack) {
|
|
22
|
+
throw new Error(e.message + '\n\n' + e.stack);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
throw e;
|
|
26
|
+
}, 0);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public addListener(listener: ErrorListenerCallback): ErrorListenerUnbind {
|
|
31
|
+
this.listeners.push(listener);
|
|
32
|
+
|
|
33
|
+
return () => {
|
|
34
|
+
this._removeListener(listener);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private emit(e: any): void {
|
|
39
|
+
this.listeners.forEach((listener) => {
|
|
40
|
+
listener(e);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private _removeListener(listener: ErrorListenerCallback): void {
|
|
45
|
+
this.listeners.splice(this.listeners.indexOf(listener), 1);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public setUnexpectedErrorHandler(newUnexpectedErrorHandler: (e: any) => void): void {
|
|
49
|
+
this.unexpectedErrorHandler = newUnexpectedErrorHandler;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public getUnexpectedErrorHandler(): (e: any) => void {
|
|
53
|
+
return this.unexpectedErrorHandler;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public onUnexpectedError(e: any): void {
|
|
57
|
+
this.unexpectedErrorHandler(e);
|
|
58
|
+
this.emit(e);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// For external errors, we don't want the listeners to be called
|
|
62
|
+
public onUnexpectedExternalError(e: any): void {
|
|
63
|
+
this.unexpectedErrorHandler(e);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const errorHandler = new ErrorHandler();
|
|
68
|
+
|
|
69
|
+
export function setUnexpectedErrorHandler(newUnexpectedErrorHandler: (e: any) => void): void {
|
|
70
|
+
errorHandler.setUnexpectedErrorHandler(newUnexpectedErrorHandler);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function onUnexpectedError(e: any): undefined {
|
|
74
|
+
// ignore errors from cancelled promises
|
|
75
|
+
if (!isPromiseCanceledError(e)) {
|
|
76
|
+
errorHandler.onUnexpectedError(e);
|
|
77
|
+
}
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function onUnexpectedExternalError(e: any): undefined {
|
|
82
|
+
// ignore errors from cancelled promises
|
|
83
|
+
if (!isPromiseCanceledError(e)) {
|
|
84
|
+
errorHandler.onUnexpectedExternalError(e);
|
|
85
|
+
}
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface SerializedError {
|
|
90
|
+
readonly $isError: true;
|
|
91
|
+
readonly name: string;
|
|
92
|
+
readonly message: string;
|
|
93
|
+
readonly stack: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function transformErrorForSerialization(error: Error): SerializedError;
|
|
97
|
+
export function transformErrorForSerialization(error: any): any;
|
|
98
|
+
export function transformErrorForSerialization(error: any): any {
|
|
99
|
+
if (error instanceof Error) {
|
|
100
|
+
const { name, message } = error;
|
|
101
|
+
const stack: string = (error as any).stacktrace || (error as any).stack;
|
|
102
|
+
return {
|
|
103
|
+
$isError: true,
|
|
104
|
+
name,
|
|
105
|
+
message,
|
|
106
|
+
stack,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// return as is
|
|
111
|
+
return error;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// see https://github.com/v8/v8/wiki/Stack%20Trace%20API#basic-stack-traces
|
|
115
|
+
export interface V8CallSite {
|
|
116
|
+
getThis(): any;
|
|
117
|
+
getTypeName(): string;
|
|
118
|
+
getFunction(): string;
|
|
119
|
+
getFunctionName(): string;
|
|
120
|
+
getMethodName(): string;
|
|
121
|
+
getFileName(): string;
|
|
122
|
+
getLineNumber(): number;
|
|
123
|
+
getColumnNumber(): number;
|
|
124
|
+
getEvalOrigin(): string;
|
|
125
|
+
isToplevel(): boolean;
|
|
126
|
+
isEval(): boolean;
|
|
127
|
+
isNative(): boolean;
|
|
128
|
+
isConstructor(): boolean;
|
|
129
|
+
toString(): string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const canceledName = 'Canceled';
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Checks if the given error is a promise in canceled state
|
|
136
|
+
*/
|
|
137
|
+
export function isPromiseCanceledError(error: any): boolean {
|
|
138
|
+
return error instanceof Error && error.name === canceledName && error.message === canceledName;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Returns an error that signals cancellation.
|
|
143
|
+
*/
|
|
144
|
+
export function canceled(): Error {
|
|
145
|
+
const error = new Error(canceledName);
|
|
146
|
+
error.name = error.message;
|
|
147
|
+
return error;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function illegalArgument(name?: string): Error {
|
|
151
|
+
if (name) {
|
|
152
|
+
return new Error(`Illegal argument: ${name}`);
|
|
153
|
+
} else {
|
|
154
|
+
return new Error('Illegal argument');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function illegalState(name?: string): Error {
|
|
159
|
+
if (name) {
|
|
160
|
+
return new Error(`Illegal state: ${name}`);
|
|
161
|
+
} else {
|
|
162
|
+
return new Error('Illegal state');
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function readonly(name?: string): Error {
|
|
167
|
+
return name
|
|
168
|
+
? new Error(`readonly property '${name} cannot be changed'`)
|
|
169
|
+
: new Error('readonly property cannot be changed');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function disposed(what: string): Error {
|
|
173
|
+
const result = new Error(`${what} has been disposed`);
|
|
174
|
+
result.name = 'DISPOSED';
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function getErrorMessage(err: any): string {
|
|
179
|
+
if (!err) {
|
|
180
|
+
return 'Error';
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (err.message) {
|
|
184
|
+
return err.message;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (err.stack) {
|
|
188
|
+
return err.stack.split('\n')[0];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return String(err);
|
|
192
|
+
}
|