From 914eb5f1805680fd5dce378f4713242d8e0e4822 Mon Sep 17 00:00:00 2001 From: Richard Simpson Date: Tue, 15 Mar 2022 21:34:07 +0000 Subject: [PATCH] address pr feedback --- packages/@aws-cdk/aws-synthetics/lib/code.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/@aws-cdk/aws-synthetics/lib/code.ts b/packages/@aws-cdk/aws-synthetics/lib/code.ts index 63369daefd3db..2d93ab105c936 100644 --- a/packages/@aws-cdk/aws-synthetics/lib/code.ts +++ b/packages/@aws-cdk/aws-synthetics/lib/code.ts @@ -129,15 +129,16 @@ export class AssetCode extends Code { * @param handler the canary handler */ private validateCanaryAsset(scope: Construct, handler: string, family: RuntimeFamily) { + if (!this.asset) { + throw new Error("'validateCanaryAsset' must be called after 'this.asset' is instantiated"); + } + // Get the staged (or copied) asset path. const assetOutdir = cdk.Stage.of(scope)?.assetOutdir; - let assetPath = this.assetPath; - if (assetOutdir) { - assetPath = path.join(assetOutdir, this.asset!.assetPath); - } + const assetPath = assetOutdir ? path.join(assetOutdir, this.asset.assetPath) : this.assetPath; if (path.extname(this.assetPath) !== '.zip') { - if (this.asset!.isFile) { + if (this.asset.isFile) { throw new Error(`Asset must be a .zip file or a directory (${this.assetPath})`); } const filename = handler.split('.')[0];