|
| 1 | +"use strict"; |
| 2 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 | +exports.AzureResourceError = exports.WebRequestError = exports.FileIOError = exports.ValidationError = exports.ChangeContextException = exports.ChangeParamsException = exports.InvocationException = exports.ExecutionException = exports.UnexpectedConversion = exports.UnexpectedExitException = exports.NotImplementedException = exports.BaseException = void 0; |
| 4 | +const state_1 = require("./constants/state"); |
| 5 | +class BaseException extends Error { |
| 6 | + constructor(message = undefined, innerException = undefined) { |
| 7 | + super(); |
| 8 | + this._innerException = innerException ? innerException : undefined; |
| 9 | + this.message = message ? message : ""; |
| 10 | + } |
| 11 | + GetInnerException() { |
| 12 | + return this._innerException; |
| 13 | + } |
| 14 | + GetTraceback() { |
| 15 | + let errorMessages = [this.message]; |
| 16 | + let innerException = this._innerException; |
| 17 | + while (innerException !== undefined && innerException instanceof BaseException) { |
| 18 | + errorMessages.push(innerException.message); |
| 19 | + innerException = innerException._innerException; |
| 20 | + } |
| 21 | + if (innerException !== undefined && innerException instanceof Error) { |
| 22 | + errorMessages.push(innerException.message); |
| 23 | + errorMessages.push(innerException.stack); |
| 24 | + } |
| 25 | + else if (innerException !== undefined) { |
| 26 | + errorMessages.push(String(innerException)); |
| 27 | + } |
| 28 | + return errorMessages; |
| 29 | + } |
| 30 | + PrintTraceback(printer) { |
| 31 | + const traceback = this.GetTraceback(); |
| 32 | + for (let i = 0; i < traceback.length; i++) { |
| 33 | + const prefix = " ".repeat(i * 2); |
| 34 | + printer(`${prefix}${traceback[i]}`); |
| 35 | + } |
| 36 | + } |
| 37 | +} |
| 38 | +exports.BaseException = BaseException; |
| 39 | +class NotImplementedException extends BaseException { |
| 40 | +} |
| 41 | +exports.NotImplementedException = NotImplementedException; |
| 42 | +class UnexpectedExitException extends BaseException { |
| 43 | + constructor(state = state_1.StateConstant.Failed) { |
| 44 | + super(state_1.StateConstant[state]); |
| 45 | + } |
| 46 | +} |
| 47 | +exports.UnexpectedExitException = UnexpectedExitException; |
| 48 | +class UnexpectedConversion extends BaseException { |
| 49 | + constructor(constantField, value) { |
| 50 | + super(`Failed to convert ${value} to ${constantField}`); |
| 51 | + } |
| 52 | +} |
| 53 | +exports.UnexpectedConversion = UnexpectedConversion; |
| 54 | +class ExecutionException extends BaseException { |
| 55 | + constructor(state, executionStage, innerException) { |
| 56 | + let errorMessage = `Execution Exception (state: ${state_1.StateConstant[state]})`; |
| 57 | + if (executionStage !== undefined) { |
| 58 | + errorMessage += ` (step: ${executionStage})`; |
| 59 | + } |
| 60 | + super(errorMessage, innerException); |
| 61 | + } |
| 62 | +} |
| 63 | +exports.ExecutionException = ExecutionException; |
| 64 | +class InvocationException extends ExecutionException { |
| 65 | + constructor(state, innerException) { |
| 66 | + super(state, "Invocation", innerException); |
| 67 | + } |
| 68 | +} |
| 69 | +exports.InvocationException = InvocationException; |
| 70 | +class ChangeParamsException extends ExecutionException { |
| 71 | + constructor(state, innerException) { |
| 72 | + super(state, "ChangeParams", innerException); |
| 73 | + } |
| 74 | +} |
| 75 | +exports.ChangeParamsException = ChangeParamsException; |
| 76 | +class ChangeContextException extends ExecutionException { |
| 77 | + constructor(state, innerException) { |
| 78 | + super(state, "ChangeContext", innerException); |
| 79 | + } |
| 80 | +} |
| 81 | +exports.ChangeContextException = ChangeContextException; |
| 82 | +class ValidationError extends BaseException { |
| 83 | + constructor(state, field, expectation, innerException) { |
| 84 | + super(`At ${state_1.StateConstant[state]}, ${field} : ${expectation}.`, innerException); |
| 85 | + } |
| 86 | +} |
| 87 | +exports.ValidationError = ValidationError; |
| 88 | +class FileIOError extends BaseException { |
| 89 | + constructor(state, action, message, innerException) { |
| 90 | + super(`When performing file operation at ${state_1.StateConstant[state]}, ${action} : ${message}`, innerException); |
| 91 | + } |
| 92 | +} |
| 93 | +exports.FileIOError = FileIOError; |
| 94 | +class WebRequestError extends BaseException { |
| 95 | + constructor(url, verb, message, innerException) { |
| 96 | + super(`When [${verb}] ${url}, error: ${message}`, innerException); |
| 97 | + } |
| 98 | +} |
| 99 | +exports.WebRequestError = WebRequestError; |
| 100 | +class AzureResourceError extends BaseException { |
| 101 | + constructor(state, action, message, innerException) { |
| 102 | + super(`When request Azure resource at ${state_1.StateConstant[state]}, ${action} : ${message}`, innerException); |
| 103 | + } |
| 104 | +} |
| 105 | +exports.AzureResourceError = AzureResourceError; |
0 commit comments