aws / aws/aws-cdk

(cli): no need for full stack trace while validating errors

Open
#27,847 3 comments 0 reactions 0 assignees View on GitHub
feature-request p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the feature

There is a class of common user validation errors that are being handled almost as if they were internal failures in CDK. Rather than CDK simply emit a validation error such as "Error: There is already a Construct with name 'SomeResourceName' on line 23 of xyz.ts", CDK instead throws an ugly exception with full internal stack trace, implying that something much more significant has happened. The error message is more alarming than necessary and less readable than would be ideal.

An example is:

> Error: There is already a Construct with name 'SomeResourceName' in some-class [some-name]

The error in this case is a simple, and perhaps common, mistake made by the CDK user and that is to have accidentally given 2 different resources the same name (perhaps as a result of an errant copy/paste).

The `cdk deploy` output looks something like this:

```
/Users/me/src/someproject/node_modules/constructs/src/construct.ts:447
throw new Error(`There is already a Construct with name '${childName}' in ${typeName}${name.length > 0 ? ' [' + name + ']' : ''}`);
^
Error: There is already a Construct with name 'SomeResourceName' in SomeClass [some-class]
at Node.addChild (/Users/me/src/someproject/node_modules/constructs/src/construct.ts:447:13)
at new Node (/Users/me/src/someproject/node_modules/constructs/src/construct.ts:71:17)
at new Construct (/Users/me/src/someproject/node_modules/constructs/src/construct.ts:499:17)
at new Resource (/Users/me/src/someproject/node_modules/aws-cdk-lib/core/lib/resource.js:1:1309)
at new SecurityGroupBase (/Users/me/src/someproject/node_modules/aws-cdk-lib/aws-ec2/lib/security-group.js:1:1051)
at new SecurityGroup (/Users/me/src/someproject/node_modules/aws-cdk-lib/aws-ec2/lib/security-group.js:1:5332)
at new SomeResource (/Users/me/src/someproject/lib/xxx.ts:244:35)
at Object. (/Users/me/src/someproject/bin/xxx.ts:11:1)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module.m._compile (/Users/me/src/someproject/node_modules/ts-node/src/index.ts:1618:23)

Subprocess exited with error 1
```

### Use Case

Simple user errors result in error messages that are much less readable than would be ideal.

### Proposed Solution

Emit the error message with source line number, minus all the stack trace.

### Other Information

_No response_

### Acknowledgements

- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

### CDK version used

2.104.0 (build 3b99abe)

### Environment details (OS name and version, etc.)

Mac OS X

Contributor guide

Open the contributing guide

Research direction

Start by tracing how `cdk deploy` handles errors and how the validation error is raised in `constructs/src/construct.ts`. Done means common validation errors retain a useful source line number while omitting the internal stack trace from the CLI output.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli, developer-experience
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.