Skip to content

Commit c0087cc

Browse files
committed
Handle more bad data in prod
1 parent e93fa2f commit c0087cc

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

data-migration/src/migrators/challengeMigrator.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,40 @@ class ChallengeMigrator extends BaseMigrator {
196196
}
197197
}
198198

199+
if (record.tags !== undefined) {
200+
if (Array.isArray(record.tags)) {
201+
const cleanedTags = [];
202+
203+
for (const rawTag of record.tags) {
204+
if (rawTag === null || rawTag === undefined) {
205+
continue;
206+
}
207+
208+
if (typeof rawTag !== 'string') {
209+
this.manager.logger.warn(`Skipping invalid tag value for challenge ${record[this.getIdField()]}; expected string, received ${typeof rawTag}`);
210+
continue;
211+
}
212+
213+
const trimmedTag = rawTag.trim();
214+
if (!trimmedTag || trimmedTag.toLowerCase() === 'null') {
215+
continue;
216+
}
217+
218+
cleanedTags.push(trimmedTag);
219+
}
220+
221+
record.tags = cleanedTags;
222+
} else if (record.tags === null) {
223+
record.tags = [];
224+
} else if (typeof record.tags === 'string') {
225+
const trimmedTag = record.tags.trim();
226+
record.tags = trimmedTag && trimmedTag.toLowerCase() !== 'null' ? [trimmedTag] : [];
227+
} else {
228+
this.manager.logger.warn(`Replacing unexpected tags value for challenge ${record[this.getIdField()]}; defaulting to empty array`);
229+
record.tags = [];
230+
}
231+
}
232+
199233
return record;
200234
}
201235

0 commit comments

Comments
 (0)