Misleading error message for deprecated `prepare()`
See original GitHub issueIn CDKv2, lifecycle method prepare()
was deprecated. Implementing such method in a construct correctly reports an error message. However, the error message is misleading:
Error: the construct “Stack/Foobar” has a “prepare()” method which is no longer supported. Use “construct.node.addValidation()” to add validations to a construct
The error message suggests to use addValidation()
, which doesn’t serve the same purpose.
CDK team suggests to use Aspects to implement prepare logic in V2, e.g.:
Aspects.of(construct).add({
visit: () => doPrepare()
})
In this case, the error message could be more clear, e.g.:
Error: the construct “Stack/Foobar” has a “prepare()” method which is no longer supported. Use Aspects to add preparation logic to a construct
Reproduction Steps
Synthesize any construct implementing the prepare()
lifecycle method. Example:
import { Stack } from "aws-cdk-lib";
import { Construct } from 'constructs';
class MyConstruct extends Construct {
constructor(scope: Construct, id: string) {
super(scope, id)
}
prepare() { }
}
export class MyStack extends Stack {
constructor(scope: Construct, id: string) {
super(scope, id, props);
new MyConstruct(this, "myConstruct")
}
}
What did you expect to happen?
Clear error message suggesting the usage of Aspects:
Error: the construct “Stack/MyConstruct” has a “prepare()” method which is no longer supported. Use Aspects to add preparation logic to a construct
What actually happened?
Misleading error message, suggesting using addValidation
as a workaround:
Error: the construct “Stack/MyConstruct” has a “prepare()” method which is no longer supported. Use “construct.node.addValidation()” to add validations to a construct
Environment
- CDK CLI Version: 2.0.0-rc.1 (build 983379b)
- Framework Version: 2.0.0-rc.1
- Node.js Version: v15.12.0
- OS: MacOS Catalina 10.15.7
- Language (Version): TypeScript (3.9.9)
Other
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
I am unassigning and marking this issue as
p2
, which means that we are unable to work on this immediately.We use +1s to help prioritize our work, and are happy to revaluate this issue based on community feedback. You can reach out to the cdk.dev community on Slack to solicit support for reprioritization.
Closing this issue as it hasn’t seen activity for a while. Please add a comment @mentioning a maintainer to reopen.