Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/util/common/errors.ts
13397 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
import { safeStringify } from '../vs/base/common/objects';
7
8
export namespace ErrorUtils {
9
10
export function fromUnknown(error: unknown): Error {
11
if (error instanceof Error) {
12
return error;
13
}
14
15
if (typeof error === 'string') {
16
return new Error(error);
17
}
18
19
return new Error(`An unexpected error occurred: ${safeStringify(error)}`);
20
}
21
22
export function toString(error: Error) {
23
return error.stack ? error.stack : error.message;
24
}
25
26
}
27
28