microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
remove-unused-debugging-code

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/common/error/errorHelper.ts

64lines · modeblame

17161993Meena Kunnathur Balakrishnan10 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
34472878RedMickey5 years ago4import { InternalError, NestedError, InternalErrorLevel } from "./internalError";
5import { InternalErrorCode } from "./internalErrorCode";
6import { ERROR_STRINGS } from "./errorStrings";
17161993Meena Kunnathur Balakrishnan10 years ago7
8export class ErrorHelper {
3c172a05Artem Egorov8 years ago9public static ERROR_STRINGS = ERROR_STRINGS;
34472878RedMickey5 years ago10public static getInternalError(
11errorCode: InternalErrorCode,
12...optionalArgs: any[]
13): InternalError {
09f6024fHeniker4 years ago14const message = ErrorHelper.getErrorMessage(errorCode, ...optionalArgs);
34472878RedMickey5 years ago15return new InternalError(<number>errorCode, message);
17161993Meena Kunnathur Balakrishnan10 years ago16}
17
34472878RedMickey5 years ago18public static getNestedError(
19innerError: Error,
20errorCode: InternalErrorCode,
21...optionalArgs: any[]
22): NestedError {
09f6024fHeniker4 years ago23const message = ErrorHelper.getErrorMessage(errorCode, ...optionalArgs);
34472878RedMickey5 years ago24return new NestedError(<number>errorCode, message, innerError);
17161993Meena Kunnathur Balakrishnan10 years ago25}
26
190e393cMeena Kunnathur Balakrishnan10 years ago27public static wrapError(error: InternalError, innerError: Error): NestedError {
28return NestedError.getWrappedError(error, innerError);
29}
e416b901Yuri Skorokhodov7 years ago30
34472878RedMickey5 years ago31public static getWarning(message: string): InternalError {
190e393cMeena Kunnathur Balakrishnan10 years ago32return new InternalError(-1, message, InternalErrorLevel.Warning);
33}
34
34472878RedMickey5 years ago35public static getNestedWarning(innerError: Error, message: string): NestedError {
36return new NestedError(
37-1,
38message,
39innerError,
40null /* extras */,
41InternalErrorLevel.Warning,
42);
a4a7e387Meena Kunnathur Balakrishnan10 years ago43}
44
17161993Meena Kunnathur Balakrishnan10 years ago45private static getErrorMessage(errorCode: InternalErrorCode, ...optionalArgs: any[]): string {
34472878RedMickey5 years ago46return ErrorHelper.formatErrorMessage(
5b09cf97Zhen Zhen Yuan (BEYONDSOFT CONSULTING INC)7 months ago47ErrorHelper.ERROR_STRINGS[errorCode as keyof typeof ErrorHelper.ERROR_STRINGS],
34472878RedMickey5 years ago48...optionalArgs,
49);
17161993Meena Kunnathur Balakrishnan10 years ago50}
51
52private static formatErrorMessage(errorMessage: string, ...optionalArgs: any[]): string {
4f8669f9JiglioNero6 years ago53if (!errorMessage) {
54return errorMessage;
55}
a4a7e387Meena Kunnathur Balakrishnan10 years ago56
34472878RedMickey5 years ago57let result: string = <string>errorMessage;
09f6024fHeniker4 years ago58for (const [i, optionalArg] of optionalArgs.entries()) {
59result = result.replace(new RegExp(`\\{${i}\\}`, "g"), optionalArg);
4f8669f9JiglioNero6 years ago60}
17161993Meena Kunnathur Balakrishnan10 years ago61
4f8669f9JiglioNero6 years ago62return result;
17161993Meena Kunnathur Balakrishnan10 years ago63}
64}