Skip to content

Commit 3e6f10d

Browse files
authored
fix(core): messages from annotations.ts can show up as [object Object] (#28414)
**CDK Version**: 2.115.0 (build 58027ee) **Os**: macOS 14.2 (BuildVersion: 23C64) I have observed the following warning showing up in my console today when running `cdk`: > [Warning at /CdkStack/AuthorizerFunction] [object Object] I was able to track down where this message was generated and apply a patch to see the error in a more descriptive format. For the records the error in my case was: > addPermission() has no effect on a Lambda Function with region=${Token[TOKEN.23]}, account=${Token[TOKEN.24]}, in a Stack with region=${Token[AWS.Region.12]}, account=${Token[AWS.AccountId.8]}. Suppress this warning if this is is intentional, or pass sameEnvironment=true to fromFunctionAttributes() if you would like to add the permissions. [ack: UnclearLambdaEnvironment] The fix proposed here makes sure that if I am not sure this is the best way to fix this issue. The signature of the `addMessage` seems to expect a `string` for the `message` value, so maybe the error needs to be corrected downstream where the `addMessage` call is made (which judging from the stack trace seems to come from `aws-cdk-lib/aws-lambda/lib/function-base.js`). Thoughts? ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 7a721d3 commit 3e6f10d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/aws-cdk-lib/core/lib/annotations.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ export class Annotations {
143143
private addMessage(level: string, message: string) {
144144
const isNew = !this.scope.node.metadata.find((x) => x.data === message);
145145
if (isNew) {
146-
this.scope.node.addMetadata(level, message, { stackTrace: this.stackTraces });
146+
let normalizedMessage = typeof message === 'string' ? message : JSON.stringify(message);
147+
this.scope.node.addMetadata(level, normalizedMessage, { stackTrace: this.stackTraces });
147148
}
148149
}
149150
}
@@ -259,4 +260,4 @@ function removeWarning(construct: IConstruct, id: string) {
259260

260261
function ackTag(id: string) {
261262
return `[ack: ${id}]`;
262-
}
263+
}

0 commit comments

Comments
 (0)