File tree 2 files changed +25
-2
lines changed
2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { Console } from 'node:console' ;
2
2
import { randomInt } from 'node:crypto' ;
3
- import { Utility } from '@aws-lambda-powertools/commons' ;
3
+ import { Utility , isNullOrUndefined } from '@aws-lambda-powertools/commons' ;
4
4
import type {
5
5
AsyncHandler ,
6
6
HandlerMethodDecorator ,
@@ -777,6 +777,9 @@ class Logger extends Utility implements LoggerInterface {
777
777
additionalAttributes : LogAttributes
778
778
) : void {
779
779
for ( const item of extraInput ) {
780
+ if ( isNullOrUndefined ( item ) ) {
781
+ continue ;
782
+ }
780
783
if ( item instanceof Error ) {
781
784
additionalAttributes . error = item ;
782
785
} else if ( typeof item === 'string' ) {
Original file line number Diff line number Diff line change @@ -601,7 +601,7 @@ describe('Working with keys', () => {
601
601
602
602
it ( 'logs a warning when using both the deprecated persistentLogAttributes and persistentKeys options' , ( ) => {
603
603
// Prepare
604
- const logger = new Logger ( {
604
+ new Logger ( {
605
605
persistentKeys : {
606
606
foo : 'bar' ,
607
607
} ,
@@ -739,4 +739,24 @@ describe('Working with keys', () => {
739
739
} )
740
740
) ;
741
741
} ) ;
742
+
743
+ it . each ( [ { value : null } , { value : undefined } ] ) (
744
+ 'handles null and undefined values when passing them to the log method ($value)' ,
745
+ ( { value } ) => {
746
+ // Prepare
747
+ const logger = new Logger ( ) ;
748
+
749
+ // Act
750
+ // @ts -expect-error - these values are already forbidden by TypeScript, but JavaScript-only customers might pass them
751
+ logger . info ( 'foo' , value ) ;
752
+
753
+ // Assess
754
+ expect ( console . info ) . toHaveLoggedNth (
755
+ 1 ,
756
+ expect . objectContaining ( {
757
+ message : 'foo' ,
758
+ } )
759
+ ) ;
760
+ }
761
+ ) ;
742
762
} ) ;
You can’t perform that action at this time.
0 commit comments