Skip to content

Commit

Permalink
fix: more informative error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ybelMekk committed Apr 21, 2022
1 parent 623d50f commit d226b86
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/cosign/cli/attach/attestation.go
Expand Up @@ -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
Expand Down

0 comments on commit d226b86

Please sign in to comment.