From 988642d4985c95dd9e0d40839627a0df5c33bf80 Mon Sep 17 00:00:00 2001 From: Ross Simpson Date: Wed, 28 Jun 2023 12:39:56 +1200 Subject: [PATCH] Detect and throw an error if the creds can't be set in the Keyring Currently an error when setting the item misleadingly results in the success message. There's nothing in the Keyring docs about this (`Set` doesn't return an error), but I've found that `nil` is returned when the call is successful, and an error is returned otherwise. Unsure if this is good Golang practice or not. --- cmd/add.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/add.go b/cmd/add.go index 6d5b68e..5024c96 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -175,12 +175,17 @@ var addCmd = &cobra.Command{ log.Fatalf("failed to open keyring backend: %s", strings.ToLower(err.Error())) } - _ = ring.Set(keyring.Item{ + resp := ring.Set(keyring.Item{ Key: fmt.Sprintf("%s-%s", profileName, authType), Data: []byte(authValue), }) - fmt.Println("\nSuccess! Credentials have been set and are now ready for use!") + if resp == nil { + fmt.Println("\nSuccess! Credentials have been set and are now ready for use!") + } else { + // error of some sort + log.Fatal("Error adding credentials to keyring: ", resp) + } }, }