From 7a7119ec8979e0de26f5a76940ab6972f53850ba Mon Sep 17 00:00:00 2001 From: Harsh Modi Date: Wed, 12 Jun 2024 04:41:19 +0000 Subject: [PATCH] fix: Ignore empty annotations in the jq query When building OCI images, we use a newline separated file in the form "a=b\nb=c\nd=e". However, if this file has a trailing newline, you get a pretty confusing error like "jq: error (at :37): Cannot use null (null) as object key" because jq splits that final newline into an empty string, and further tries to split it on the "=" which results in a null key. Instead, filter out any empty strings. --- oci/private/image.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oci/private/image.sh b/oci/private/image.sh index 539c2a8e..195146c0 100644 --- a/oci/private/image.sh +++ b/oci/private/image.sh @@ -166,7 +166,7 @@ for ARG in "$@"; do --annotations=*) get_manifest | jq --rawfile annotations "${ARG#--annotations=}" \ - '.annotations += ($annotations | split("\n") | map(. | split("=")) | map({key: .[0], value: .[1:] | join("=")}) | from_entries)' | + '.annotations += ([($annotations | split("\n") | .[] | select(. != ""))] | map(. | split("=")) | map({key: .[0], value: .[1:] | join("=")}) | from_entries)' | update_manifest ;; *)