|
1 | 1 | import { ServiceException } from "@smithy/core/client"; |
| 2 | +import { join } from "node:path"; |
2 | 3 | import { ERROR_SOURCE, type ErrorSource } from "./types"; |
3 | 4 |
|
4 | 5 | export interface AgentCoreCLIErrorOptions extends ErrorOptions { |
@@ -74,3 +75,70 @@ export class NotImplementedError extends AgentCoreCLIError { |
74 | 75 | super(message ?? "not implemented yet", { ...options, source: ERROR_SOURCE.INTERNAL }); |
75 | 76 | } |
76 | 77 | } |
| 78 | + |
| 79 | +/** Error raised when detecting an invalid environment */ |
| 80 | +export class InvalidEnvironmentError extends AgentCoreCLIError { |
| 81 | + constructor(message?: string, options?: Omit<AgentCoreCLIErrorOptions, "source">) { |
| 82 | + super(message, { ...options, source: ERROR_SOURCE.USER }); |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +export class SourceResolutionError extends InputValidationError { |
| 87 | + constructor(message: string, options?: ErrorOptions) { |
| 88 | + super(message, options); |
| 89 | + this.name = "SourceResolutionError"; |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +// TODO: attach telemetry metadata to this error class. |
| 94 | +export class DeserializationError extends Error { |
| 95 | + constructor(path: string, options?: { cause?: unknown }) { |
| 96 | + super(`Failed to deserialize JSON at "${path}"`, options); |
| 97 | + this.name = "DeserializationError"; |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +/** Thrown when scaffolding would overwrite a file that already exists. */ |
| 102 | +export class ProjectFileExistsError extends AgentCoreCLIError { |
| 103 | + constructor(public readonly path: string) { |
| 104 | + super(`Refusing to overwrite existing file: ${path}`, { |
| 105 | + source: ERROR_SOURCE.USER, |
| 106 | + meta: { path }, |
| 107 | + }); |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +/** Thrown when scaffolding would nest a new project inside an existing AgentCore project. */ |
| 112 | +export class NestedProjectError extends AgentCoreCLIError { |
| 113 | + constructor(public readonly projectRoot: string) { |
| 114 | + super( |
| 115 | + `cannot create a project inside an existing AgentCore project (found ${join(projectRoot, "agentcore", "agentcore.json")})`, |
| 116 | + { source: ERROR_SOURCE.USER, meta: { projectRoot } }, |
| 117 | + ); |
| 118 | + } |
| 119 | +} |
| 120 | + |
| 121 | +/** Thrown when an asset is missing from the compiled executable, indicating a packaging bug. */ |
| 122 | +export class EmbeddedAssetNotFoundError extends AgentCoreCLIError { |
| 123 | + constructor(public readonly assetPath: string) { |
| 124 | + super(`Embedded asset not found: ${assetPath}`, { meta: { assetPath } }); |
| 125 | + } |
| 126 | +} |
| 127 | + |
| 128 | +export class RuntimeInvokeInterruptedError extends AgentCoreCLIError { |
| 129 | + readonly reported: boolean; |
| 130 | + |
| 131 | + constructor(cause?: unknown, reported = false) { |
| 132 | + super("The operation was aborted", { cause, exitCode: 130 }); |
| 133 | + this.name = "AbortError"; |
| 134 | + this.reported = reported; |
| 135 | + } |
| 136 | +} |
| 137 | + |
| 138 | +export class RuntimeInvokeResponseError extends AgentCoreCLIError { |
| 139 | + readonly reported = true; |
| 140 | + |
| 141 | + constructor(message: string, cause?: unknown) { |
| 142 | + super(message, { cause }); |
| 143 | + } |
| 144 | +} |
0 commit comments