From f5549f3980fb7f1ade3313e027d1fd086459fe8b Mon Sep 17 00:00:00 2001 From: Heiko Voigt <184958+hvoigt@users.noreply.github.com> Date: Wed, 17 Feb 2021 10:53:06 +0100 Subject: [PATCH] handle key not found error (#2) If a key is not found client.Logical().Read(k) will return (nil, nil). Lets gracefully handle this case and tell the user what is wrong. --- main.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.go b/main.go index 60841e6..b15f250 100644 --- a/main.go +++ b/main.go @@ -166,6 +166,10 @@ func getSecretsFromVault() ([]token, error) { return nil, fmt.Errorf("Unable to read from key %q: %s", k, err) } + if data == nil { + return nil, fmt.Errorf("Key %q not found", k) + } + if data.Data[cfg.Field] == nil { return nil, fmt.Errorf("The key %q does not have a field named %q.", k, cfg.Field) }