cdk-eks-blueprints icon indicating copy to clipboard operation
cdk-eks-blueprints copied to clipboard

addon-utils: dependable crashes if the decorated method returns void

Open RadekDvorak opened this issue 3 years ago • 1 comments

Describe the bug

The decorator dependable incorrectly assume that the decorated method returns a Promise. In fact void | Promise<Construct> is allowed as a return type. That is why result.then fails.

Expected Behavior

Cdk synth completes successfuly

Current Behavior

CDK synth crashes

2022-09-12 13:51:01.228  ERROR [main   printFatalErrorUponExit] Error: TypeError: Cannot read properties of undefined (reading 'then')
    at somewhere/node_modules/@aws-quickstart/eks-blueprints/lib/utils/addon-utils.ts:45:31
    at processTicksAndRejections (node:internal/process/task_queues:95:5) 

Please note how the line number is obfuscated by subsequent error re-throw.

Reproduction Steps

import {
    AwsLoadBalancerControllerAddOn,
    ClusterInfo,
    HelmAddOn,
    HelmAddOnUserProps
} from "@aws-quickstart/eks-blueprints";
import {dependable} from "@aws-quickstart/eks-blueprints/dist/utils";


const defaultProps: HelmAddOnUserProps = {
    name: 'istio-gateway',
    chart: 'gateway',
    release: "istio-gateway",
    version: '1.14.3',
    repository: 'https://istio-release.storage.googleapis.com/charts',
    namespace: 'istio-system',
};


export class FooAddOn extends HelmAddOn {

    options: HelmAddOnUserProps

    constructor(props?: HelmAddOnUserProps) {
        super({...defaultProps as any, ...props})

        this.options = props ?? {...defaultProps}
    }

    @dependable(AwsLoadBalancerControllerAddOn.name)
    deploy(clusterInfo: ClusterInfo): void {
        this.addHelmChart(clusterInfo, this.options.values)
    }
}

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.41.0 (build 6ad48a3)

EKS Blueprints Version

1.2.0

Node.js Version

v18.7.0

Environment details (OS name and version, etc.)

Gentoo Linux

Other information

This issue can be worked around.

const chart = this.addHelmChart(clusterInfo, values);
return Promise.resolve(chart);

RadekDvorak avatar Sep 12 '22 14:09 RadekDvorak

I had this same issue and was ripping indivisible hair out of my now bald head. The workaround worked fine, though. Thanks @RadekDvorak

PerArneng avatar Nov 28 '22 18:11 PerArneng

Closing this issue.

elamaran11 avatar Oct 12 '23 12:10 elamaran11