diff --git a/src/cli/cdk/toolkit-lib/wrapper.ts b/src/cli/cdk/toolkit-lib/wrapper.ts index 4444f2795..1fff8f724 100644 --- a/src/cli/cdk/toolkit-lib/wrapper.ts +++ b/src/cli/cdk/toolkit-lib/wrapper.ts @@ -1,6 +1,6 @@ import { CONFIG_DIR } from '../../../lib'; import { CDK_APP_ENTRY, CDK_PROJECT_DIR } from '../../constants'; -import { getErrorMessage, isChangesetInProgressError } from '../../errors'; +import { isChangesetInProgressError } from '../../errors'; import type { CdkToolkitWrapperOptions, DeployOptions, DestroyOptions, DiffOptions, ListOptions } from './types'; import { BaseCredentials, @@ -36,18 +36,10 @@ async function withErrorContext(context: string, operation: () => Promise) try { return await operation(); } catch (err) { - const message = getErrorMessage(err); - const stack = err instanceof Error ? err.stack : undefined; - const cause = err instanceof Error ? err.cause : undefined; - - const error = new Error(`CDK ${context} failed: ${message}`); - if (stack) { - error.stack = `CDK ${context} failed: ${message}\n\nOriginal stack:\n${stack}`; - } - if (cause) { - error.cause = cause; + if (err instanceof Error) { + err.message = `CDK ${context} failed: ${err.message}`; } - throw error; + throw err; } } diff --git a/src/cli/commands/deploy/actions.ts b/src/cli/commands/deploy/actions.ts index 13f696587..65dbcddb1 100644 --- a/src/cli/commands/deploy/actions.ts +++ b/src/cli/commands/deploy/actions.ts @@ -155,7 +155,7 @@ export async function handleDeploy(options: ValidatedDeployOptions): Promise { // No deployed state file — no existing stack } if (!hasExistingStack) { - throw new Error( + throw new ValidationError( 'No resources defined in project. Add at least one resource (agent, memory, evaluator, or gateway) before deploying.' ); } @@ -144,7 +145,7 @@ function validateRuntimeNames(projectSpec: AgentCoreProjectSpec): void { if (agentName) { const combinedName = `${projectName}_${agentName}`; if (combinedName.length > MAX_RUNTIME_NAME_LENGTH) { - throw new Error( + throw new ValidationError( `Runtime name too long: "${combinedName}" (${combinedName.length} chars). ` + `AWS limits runtime names to ${MAX_RUNTIME_NAME_LENGTH} characters. ` + `Shorten the project name or agent name in agentcore.json.`