| | | 1 | | /** |
| | | 2 | | * Base class for all domain-specific errors in the application. |
| | | 3 | | */ |
| | | 4 | | export class DomainError extends Error { |
| | | 5 | | constructor(message: string) { |
| | 70 | 6 | | super(message); |
| | 70 | 7 | | this.name = this.constructor.name; |
| | 70 | 8 | | Error.captureStackTrace(this, this.constructor); |
| | | 9 | | } |
| | | 10 | | } |
| | | 11 | | |
| | | 12 | | /** |
| | | 13 | | * Error thrown when required arguments are missing or invalid. |
| | | 14 | | */ |
| | | 15 | | export class InvalidArgumentError extends DomainError {} |
| | | 16 | | |
| | | 17 | | /** |
| | | 18 | | * Error thrown when a required dependency is missing. |
| | | 19 | | */ |
| | | 20 | | export class DependencyMissingError extends DomainError {} |
| | | 21 | | |
| | | 22 | | /** |
| | | 23 | | * Error thrown when a secret operation fails. |
| | | 24 | | */ |
| | | 25 | | export class SecretOperationError extends DomainError {} |
| | | 26 | | |
| | | 27 | | /** |
| | | 28 | | * Error thrown when an environment file operation fails. |
| | | 29 | | */ |
| | | 30 | | export class EnvironmentFileError extends DomainError {} |
| | | 31 | | |
| | | 32 | | /** |
| | | 33 | | * Error thrown when a parameter cannot be found. |
| | | 34 | | */ |
| | | 35 | | export class ParameterNotFoundError extends DomainError { |
| | | 36 | | constructor(paramName: string) { |
| | 0 | 37 | | super(`Parameter not found: ${paramName}`); |
| | 0 | 38 | | this.paramName = paramName; |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | readonly paramName: string; |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | /** |
| | | 45 | | * Error thrown when AWS credentials or the security token are expired or invalid. |
| | | 46 | | */ |
| | | 47 | | export class ExpiredCredentialsError extends DomainError { |
| | | 48 | | readonly cause?: unknown; |
| | | 49 | | |
| | | 50 | | constructor(cause?: unknown) { |
| | 4 | 51 | | super( |
| | | 52 | | 'AWS credentials are expired or invalid. Your security token or SSO ' + |
| | | 53 | | 'session may have expired. Refresh your credentials and retry ' + |
| | | 54 | | '(for SSO, run: aws sso login).', |
| | | 55 | | ); |
| | 4 | 56 | | this.cause = cause; |
| | | 57 | | } |
| | | 58 | | } |
| | | 59 | | |
| | | 60 | | /** |
| | | 61 | | * Error thrown when the AWS SSO session could not be resolved or loaded. |
| | | 62 | | */ |
| | | 63 | | export class SsoSessionExpiredError extends DomainError { |
| | | 64 | | readonly profileName?: string; |
| | | 65 | | readonly cause?: unknown; |
| | | 66 | | |
| | | 67 | | constructor(profileName?: string, cause?: unknown) { |
| | 15 | 68 | | super(SsoSessionExpiredError.buildMessage(profileName)); |
| | 15 | 69 | | this.profileName = profileName; |
| | 15 | 70 | | this.cause = cause; |
| | | 71 | | } |
| | | 72 | | |
| | | 73 | | private static buildMessage(profileName?: string): string { |
| | 15 | 74 | | if (profileName) { |
| | 13 | 75 | | return ( |
| | | 76 | | `Your AWS SSO session for profile '${profileName}' could not be ` + |
| | | 77 | | `loaded or has expired. Run: aws sso login --profile ${profileName} ` + |
| | | 78 | | 'and then re-run this command.' |
| | | 79 | | ); |
| | | 80 | | } |
| | 2 | 81 | | return ( |
| | | 82 | | 'Your AWS SSO session could not be loaded or has expired. Run: ' + |
| | | 83 | | 'aws sso login and then re-run this command.' |
| | | 84 | | ); |
| | | 85 | | } |
| | | 86 | | } |
| | | 87 | | |
| | | 88 | | /** |
| | | 89 | | * Describes a single secret that could not be resolved during a pull operation. |
| | | 90 | | */ |
| | | 91 | | export type SecretFetchFailure = { |
| | | 92 | | envVar: string; |
| | | 93 | | path: string; |
| | | 94 | | reason: string; |
| | | 95 | | }; |
| | | 96 | | |
| | | 97 | | /** |
| | | 98 | | * Error thrown when one or more secrets could not be fetched during a pull. |
| | | 99 | | */ |
| | | 100 | | export class SecretsFetchError extends DomainError { |
| | 10 | 101 | | constructor(readonly failures: ReadonlyArray<SecretFetchFailure>) { |
| | 10 | 102 | | super('Some secrets could not be fetched'); |
| | | 103 | | } |
| | | 104 | | } |