From 3f3c8343d6ec5e58659f0681ccb8f9d6b2996e70 Mon Sep 17 00:00:00 2001 From: Anna Mager Date: Thu, 15 Aug 2024 12:29:02 +0200 Subject: [PATCH] fix(testResult): transform undefined to null when serializing test result --- core/src/plugins/kubernetes/test-results.ts | 6 +++++- core/src/util/serialization.ts | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/src/plugins/kubernetes/test-results.ts b/core/src/plugins/kubernetes/test-results.ts index 4efbc2a949..1822df8444 100644 --- a/core/src/plugins/kubernetes/test-results.ts +++ b/core/src/plugins/kubernetes/test-results.ts @@ -22,6 +22,7 @@ import type { TestActionHandler } from "../../plugin/action-types.js" import { runResultToActionState } from "../../actions/base.js" import type { HelmPodTestAction } from "./helm/config.js" import type { KubernetesTestAction } from "./kubernetes-type/config.js" +import { GardenError } from "../../exceptions.js" // TODO: figure out how to get rid of the any cast export const k8sGetTestResult: TestActionHandler<"getResult", any> = async (params) => { @@ -57,7 +58,7 @@ export const k8sGetTestResult: TestActionHandler<"getResult", any> = async (para export function getTestResultKey(ctx: PluginContext, action: StoreTestResultParams["action"]) { // change the result format version if the result format changes breaking backwards-compatibility e.g. serialization format - const resultFormatVersion = 1 + const resultFormatVersion = 2 const key = `${ctx.projectName}--${action.name}--${action.versionString()}--${resultFormatVersion}` const hash = hashSync(key, { algorithm: "sha1" }) return `test-result--${hash.slice(0, 32)}` @@ -95,6 +96,9 @@ export async function storeTestResult({ ctx, log, action, result }: StoreTestRes data, }) } catch (err) { + if (!(err instanceof GardenError)) { + throw err + } log.warn(`Unable to store test result: ${err}`) } diff --git a/core/src/util/serialization.ts b/core/src/util/serialization.ts index 14d78df355..c38e89dbe1 100644 --- a/core/src/util/serialization.ts +++ b/core/src/util/serialization.ts @@ -65,11 +65,12 @@ export async function loadYamlFile(path: string): Promise { } export function serializeObject(o: any): string { - return Buffer.from(JSON.stringify(o)).toString("base64") + return Buffer.from(JSON.stringify(o === undefined ? null : o)).toString("base64") } export function deserializeObject(s: string) { - return JSON.parse(Buffer.from(s, "base64").toString()) + const parsed = JSON.parse(Buffer.from(s, "base64").toString()) + return parsed === null ? undefined : parsed } export function serializeValues(o: { [key: string]: any }): { [key: string]: string } {