From 69d51f0f513e3e13a5365b5a37db2dede8520eec Mon Sep 17 00:00:00 2001 From: Youssef Bel Mekki <38552193+ybelMekk@users.noreply.github.com> Date: Thu, 21 Apr 2022 18:45:24 +0200 Subject: [PATCH] fix: more informative error (#1778) When running the attach attestation command with empty file input the cli returns hard to understand output like: ``` file name too long Using payload from: filename.json Error: unexpected end of JSON input main.go:46: error during command execution: unexpected end of JSON input ``` By some investigation I found out that attestation file was empty, yes this is a user-error, so I recon it could be more informative as it throws the error while parsing the input making the real error a bit shaded. Signed-off-by: ybelMekk --- cmd/cosign/cli/attach/attestation.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/cosign/cli/attach/attestation.go b/cmd/cosign/cli/attach/attestation.go index 47255aa966c..e6f35c7527c 100644 --- a/cmd/cosign/cli/attach/attestation.go +++ b/cmd/cosign/cli/attach/attestation.go @@ -42,6 +42,10 @@ func AttestationCmd(ctx context.Context, regOpts options.RegistryOptions, signed return err } + if len(payload) == 0 { + return fmt.Errorf("%s payload is empty", signedPayload) + } + env := ssldsse.Envelope{} if err := json.Unmarshal(payload, &env); err != nil { return err