question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Misleading error message for deprecated `prepare()`

See original GitHub issue

In 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:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
eladbcommented, May 5, 2021

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.

0reactions
github-actions[bot]commented, Jul 20, 2021

Closing this issue as it hasn’t seen activity for a while. Please add a comment @mentioning a maintainer to reopen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deprecation checking and correction tools to prepare ... - Drupal
The execution of your module's test suite can be configured to fail when a deprecated code path (a trigger_error() with E_USER_DEPRECATED level) ...
Read more >
If something is deprecated, can I still use it? [duplicate]
It means that it is bad practice to use it. It can still be used, but eventually it will not work with other...
Read more >
Enhanced Deprecation - Java - Oracle Help Center
Deprecation is a notification to library consumers that they should migrate code from a deprecated API. In the JDK, APIs have been deprecated...
Read more >
make use of deprecated namespaces/vars easier to spot
I was hoping it would be quick and easy to add source file, line, and column info to the deprecation warning messages. It...
Read more >
warnings — Warning control — Python 3.11.1 documentation
This makes the warning refer to deprecation() 's caller, rather than to the source of deprecation() itself (since the latter would defeat the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found