@@ -72,7 +72,14 @@ const destructiveApprovals = new Map()
7272
7373function logWithLevel ( level , message , context = null ) {
7474 const timestamp = new Date ( ) . toISOString ( )
75- const contextSuffix = context ? ` | ${ JSON . stringify ( context ) } ` : ''
75+ let contextSuffix = ''
76+ if ( context ) {
77+ try {
78+ contextSuffix = ` | ${ JSON . stringify ( context , ( _ , value ) => ( typeof value === 'bigint' ? value . toString ( ) : value ) ) } `
79+ } catch ( serializeErr ) {
80+ contextSuffix = ` | ${ JSON . stringify ( { serializationError : serializeErr . message } ) } `
81+ }
82+ }
7683 const output = `[${ level } ] ${ timestamp } ${ message } ${ contextSuffix } `
7784 if ( level === LOG_LEVELS . ERROR ) {
7885 console . error ( output )
@@ -95,6 +102,14 @@ function logError (message, context) {
95102 logWithLevel ( LOG_LEVELS . ERROR , message , context )
96103}
97104
105+ function isBigIntSerializationError ( err ) {
106+ if ( ! err ) {
107+ return false
108+ }
109+ const message = err . message || `${ err } `
110+ return typeof message === 'string' && message . toLowerCase ( ) . includes ( 'serialize a bigint' )
111+ }
112+
98113async function executeWrite ( description , operation , context = { } ) {
99114 if ( DRY_RUN ) {
100115 logInfo ( `DRY_RUN active, skipping write: ${ description } ` , context )
@@ -1169,6 +1184,7 @@ async function importDynamoMember (filename, dateFilter = null) {
11691184 let total = 0
11701185 // count skipped items due to date filter
11711186 let skipped = 0
1187+ let skippedDueToErrors = 0
11721188 // store the temp json object string
11731189 let stringObject = ''
11741190 // store batch items
@@ -2225,11 +2241,18 @@ async function importElasticSearchMember (filename, dateFilter = null) {
22252241 continue
22262242 }
22272243
2228- await updateMembersWithTraitsAndSkills ( dataObj )
2229- total += 1
2244+ const updated = await updateMembersWithTraitsAndSkills ( dataObj )
2245+ if ( updated ) {
2246+ total += 1
2247+ } else {
2248+ skippedDueToErrors += 1
2249+ }
22302250 }
22312251
22322252 console . log ( `\nIt has updated ${ total } items totally, skipped ${ skipped } items` )
2253+ if ( skippedDueToErrors > 0 ) {
2254+ console . log ( `Skipped due to errors: ${ skippedDueToErrors } ` )
2255+ }
22332256
22342257 console . log ( `Finished reading the file: ${ filename } \n` )
22352258}
@@ -2750,6 +2773,10 @@ async function updateMembersWithTraitsAndSkills (memberObj) {
27502773 } ) )
27512774 } catch ( err ) {
27522775 logError ( 'Failed to update member with traits and skills' , { ...context , error : err ?. message } )
2776+ if ( isBigIntSerializationError ( err ) ) {
2777+ logWarn ( 'Skipping member update due to BigInt serialization error' , context )
2778+ return false
2779+ }
27532780 throw err
27542781 }
27552782 }
@@ -2759,9 +2786,15 @@ async function updateMembersWithTraitsAndSkills (memberObj) {
27592786 await syncMemberSkills ( memberObj . userId , memberObj . memberSkills , memberObj . handle )
27602787 } catch ( err ) {
27612788 logError ( 'Failed to sync member skills' , { ...context , error : err ?. message } )
2789+ if ( isBigIntSerializationError ( err ) ) {
2790+ logWarn ( 'Skipping member skill sync due to BigInt serialization error' , context )
2791+ return false
2792+ }
27622793 throw err
27632794 }
27642795 }
2796+
2797+ return true
27652798}
27662799
27672800async function syncMemberAddresses ( tx , userId , addresses = [ ] ) {
0 commit comments