Skip to content

Commit

Permalink
[typeorm] Catch JSON error in SIMPLE_JSON transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
corneliusludmann committed Jul 7, 2021
1 parent 9fcf39a commit 865cd57
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion components/gitpod-db/src/typeorm/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { ValueTransformer } from "typeorm/decorator/options/ValueTransformer";
import { EncryptionService } from "@gitpod/gitpod-protocol/lib/encryption/encryption-service";
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";


export namespace Transformer {
Expand Down Expand Up @@ -45,7 +46,12 @@ export namespace Transformer {
return JSON.stringify(value || defaultValue);
},
from(value: any): any {
return JSON.parse(value);
try {
return typeof value === 'object' ? value : JSON.parse(value);
} catch (e) {
log.error(`Cannot parse JSON during TypeORM transformation. Returning default value '${JSON.stringify(defaultValue)}' instead. Value: ${JSON.stringify(value)}`, e);
return defaultValue;
}
}
};
}
Expand Down

0 comments on commit 865cd57

Please sign in to comment.