Skip to content

Commit

Permalink
fix(core): messages from annotations.ts can show up as `[object Obj…
Browse files Browse the repository at this point in the history
…ect]` (#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*
  • Loading branch information
lmammino authored Dec 18, 2023
1 parent 7a721d3 commit 3e6f10d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/aws-cdk-lib/core/lib/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ export class Annotations {
private addMessage(level: string, message: string) {
const isNew = !this.scope.node.metadata.find((x) => x.data === message);
if (isNew) {
this.scope.node.addMetadata(level, message, { stackTrace: this.stackTraces });
let normalizedMessage = typeof message === 'string' ? message : JSON.stringify(message);
this.scope.node.addMetadata(level, normalizedMessage, { stackTrace: this.stackTraces });
}
}
}
Expand Down Expand Up @@ -259,4 +260,4 @@ function removeWarning(construct: IConstruct, id: string) {

function ackTag(id: string) {
return `[ack: ${id}]`;
}
}

0 comments on commit 3e6f10d

Please sign in to comment.