Skip to content

Commit 3126905

Browse files
authored
fix(deploy): preserve error typing through CDK wrapper and preflight (aws#1459)
1 parent d14504f commit 3126905

3 files changed

Lines changed: 8 additions & 15 deletions

File tree

src/cli/cdk/toolkit-lib/wrapper.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CONFIG_DIR } from '../../../lib';
22
import { CDK_APP_ENTRY, CDK_PROJECT_DIR } from '../../constants';
3-
import { getErrorMessage, isChangesetInProgressError } from '../../errors';
3+
import { isChangesetInProgressError } from '../../errors';
44
import type { CdkToolkitWrapperOptions, DeployOptions, DestroyOptions, DiffOptions, ListOptions } from './types';
55
import {
66
BaseCredentials,
@@ -36,18 +36,10 @@ async function withErrorContext<T>(context: string, operation: () => Promise<T>)
3636
try {
3737
return await operation();
3838
} catch (err) {
39-
const message = getErrorMessage(err);
40-
const stack = err instanceof Error ? err.stack : undefined;
41-
const cause = err instanceof Error ? err.cause : undefined;
42-
43-
const error = new Error(`CDK ${context} failed: ${message}`);
44-
if (stack) {
45-
error.stack = `CDK ${context} failed: ${message}\n\nOriginal stack:\n${stack}`;
46-
}
47-
if (cause) {
48-
error.cause = cause;
39+
if (err instanceof Error) {
40+
err.message = `CDK ${context} failed: ${err.message}`;
4941
}
50-
throw error;
42+
throw err;
5143
}
5244
}
5345

src/cli/commands/deploy/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export async function handleDeploy(options: ValidatedDeployOptions): Promise<Dep
155155
logger.finalize(false);
156156
return {
157157
success: false,
158-
error: new Error(
158+
error: new ValidationError(
159159
'This will delete all deployed resources and the CloudFormation stack. Run with --yes to confirm teardown.'
160160
),
161161
logPath: logger.getRelativeLogPath(),

src/cli/operations/deploy/preflight.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ConfigIO, DOCKERFILE_NAME, getDockerfilePath, requireConfigRoot, resolveCodeLocation } from '../../../lib';
2+
import { ValidationError } from '../../../lib/errors/types';
23
import type { AgentCoreProjectSpec, AwsDeploymentTarget } from '../../../schema';
34
import { validateAwsCredentials } from '../../aws/account';
45
import { LocalCdkProject } from '../../cdk/local-cdk-project';
@@ -109,7 +110,7 @@ export async function validateProject(): Promise<PreflightContext> {
109110
// No deployed state file — no existing stack
110111
}
111112
if (!hasExistingStack) {
112-
throw new Error(
113+
throw new ValidationError(
113114
'No resources defined in project. Add at least one resource (agent, memory, evaluator, or gateway) before deploying.'
114115
);
115116
}
@@ -144,7 +145,7 @@ function validateRuntimeNames(projectSpec: AgentCoreProjectSpec): void {
144145
if (agentName) {
145146
const combinedName = `${projectName}_${agentName}`;
146147
if (combinedName.length > MAX_RUNTIME_NAME_LENGTH) {
147-
throw new Error(
148+
throw new ValidationError(
148149
`Runtime name too long: "${combinedName}" (${combinedName.length} chars). ` +
149150
`AWS limits runtime names to ${MAX_RUNTIME_NAME_LENGTH} characters. ` +
150151
`Shorten the project name or agent name in agentcore.json.`

0 commit comments

Comments
 (0)