Skip to content

Commit 9dee885

Browse files
committed
Handle error seen when testing in prod
1 parent 53d15fa commit 9dee885

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

src/scripts/migrate-dynamo-data.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,14 @@ const destructiveApprovals = new Map()
7272

7373
function 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+
98113
async 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

27672800
async function syncMemberAddresses (tx, userId, addresses = []) {

src/scripts/update-member-traits.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ async function updateTraitsFromFile (filename) {
2424
let updated = 0
2525
let skippedNoMember = 0
2626
let skippedNoTraits = 0
27+
let skippedDueToErrors = 0
2728

2829
for await (const line of rl) {
2930
const trimmed = line.trim()
@@ -67,8 +68,12 @@ async function updateTraitsFromFile (filename) {
6768
memberTraits: updateData.memberTraits
6869
}
6970

70-
await updateMembersWithTraitsAndSkills(traitUpdate)
71-
updated += 1
71+
const updatedSuccessfully = await updateMembersWithTraitsAndSkills(traitUpdate)
72+
if (updatedSuccessfully) {
73+
updated += 1
74+
} else {
75+
skippedDueToErrors += 1
76+
}
7277

7378
if (processed % 100 === 0) {
7479
console.log(`Processed ${processed} lines, updated ${updated} members`)
@@ -80,6 +85,9 @@ async function updateTraitsFromFile (filename) {
8085
console.log(`Members updated: ${updated}`)
8186
console.log(`Skipped (no matching member): ${skippedNoMember}`)
8287
console.log(`Skipped (no trait changes): ${skippedNoTraits}`)
88+
if (skippedDueToErrors > 0) {
89+
console.log(`Skipped due to errors: ${skippedDueToErrors}`)
90+
}
8391
}
8492

8593
async function main () {

0 commit comments

Comments
 (0)