diff --git a/packages/aws-cdk-lib/core/lib/asset-staging.ts b/packages/aws-cdk-lib/core/lib/asset-staging.ts index 1aaca8edf1f9b..91ec93914a2f0 100644 --- a/packages/aws-cdk-lib/core/lib/asset-staging.ts +++ b/packages/aws-cdk-lib/core/lib/asset-staging.ts @@ -570,8 +570,8 @@ function sanitizeHashValue(key: string, value: any): any { url.password = ''; return url.toString(); } - } catch (e) { - if (e instanceof TypeError) { + } catch (e: any) { + if (e.name === 'TypeError') { throw new Error(`${key} must be a valid URL, got ${value}.`); } throw e; diff --git a/packages/aws-cdk-lib/core/test/staging.test.ts b/packages/aws-cdk-lib/core/test/staging.test.ts index 3f2a1cd6f86a6..6f3d904b4ed6e 100644 --- a/packages/aws-cdk-lib/core/test/staging.test.ts +++ b/packages/aws-cdk-lib/core/test/staging.test.ts @@ -543,6 +543,25 @@ describe('staging', () => { ]); }); + test('bundler throws n error when the PIP url is not a valid url', () => { + // GIVEN + const app = new App({ context: { [cxapi.NEW_STYLE_STACK_SYNTHESIS_CONTEXT]: false } }); + const stack = new Stack(app, 'stack'); + const directory = path.join(__dirname, 'fs', 'fixtures', 'test1'); + + // WHEN + expect(() => new AssetStaging(stack, 'Asset', { + sourcePath: directory, + bundling: { + image: DockerImage.fromRegistry('alpine'), + command: [DockerStubCommand.SUCCESS], + environment: { + PIP_INDEX_URL: 'NOT_A_URL', + }, + }, + })).toThrow('PIP_INDEX_URL must be a valid URL, got NOT_A_URL.'); + }); + test('bundler outputs to intermediate dir and renames to asset', () => { // GIVEN const app = new App({ context: { [cxapi.NEW_STYLE_STACK_SYNTHESIS_CONTEXT]: false } });