Skip to content

Commit c913ff1

Browse files
Tietewmrgrain
andauthored
fix(cli): [object Object] in error message when CcApiContextProviderPlugin listResources throws (#168)
Interporating `propertyMatch` directly in error message causes `[object Object]` representation because it's an object. This PR wraps it in `JSON.stringify()` to fix the message correctly. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license --------- Co-authored-by: Momo Kornher <[email protected]>
1 parent 8a73428 commit c913ff1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/aws-cdk/lib/context-providers/cc-api-provider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class CcApiContextProviderPlugin implements ContextProviderPlugin {
120120
}
121121
});
122122
} catch (err) {
123-
throw new ContextProviderError(`Could not get resources ${propertyMatch}. Error: ${err}`);
123+
throw new ContextProviderError(`Could not get resources ${JSON.stringify(propertyMatch)}. Error: ${err}`);
124124
}
125125
return resultObjs;
126126
}

packages/aws-cdk/test/context-providers/cc-api-provider.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,22 @@ test('looks up RDS instance using CC API listResources - nested prop', async ()
188188
expect(results.length).toEqual(1);
189189
});
190190

191+
test('looks up RDS instance using CC API listResources - error in CC API', async () => {
192+
// GIVEN
193+
mockCloudControlClient.on(ListResourcesCommand).rejects('No data found');
194+
195+
await expect(
196+
// WHEN
197+
provider.getValue({
198+
account: '123456789012',
199+
region: 'us-east-1',
200+
typeName: 'AWS::RDS::DBInstance',
201+
propertyMatch: { 'Endpoint.Port': '5432' },
202+
propertiesToReturn: ['DBInstanceArn', 'StorageEncrypted'],
203+
}),
204+
).rejects.toThrow('Could not get resources {"Endpoint.Port":"5432"}.'); // THEN
205+
});
206+
191207
test('error by specifying both exactIdentifier and propertyMatch', async () => {
192208
// GIVEN
193209
mockCloudControlClient.on(GetResourceCommand).resolves({

0 commit comments

Comments
 (0)