From c83b14993c0995bad99f60e48286e0962bda0f45 Mon Sep 17 00:00:00 2001 From: Vrashabh Sontakke Date: Tue, 23 Apr 2024 20:34:37 +0530 Subject: [PATCH] Enhance Identity Existance Checks with Improved Error Handling This commit enhances the `LoadSelectedIdentity` function in the [identities.go](https://github.com/openziti/ziti/blob/a60ed6ffb6d539664151584ccd01b1740fc4d2b2/ziti/util/identities.go#L241C1-L255C2) file by adding improved error handling and checks for the existence of identities in the CLI configuration. Previously, the function only threw an ambiguous error if the selected identity was not found in the CLI config. However, with this enhancement, the function now checks if there are any saved identities in the CLI config. If no identities are found, it returns an error instructing the user to log in using the `ziti edge login` command. Additionally, if the specified identity is not found, it returns an error message indicating that the identity could not be found in the CLI config and provides instructions on how to select an existing identity using `ziti edge use `. These changes improve the robustness of the function by ensuring that appropriate error messages are provided in scenarios where the user is not logged in or when the selected identity is missing. fixes #1772 thanks to @plorenz --- ziti/util/identities.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ziti/util/identities.go b/ziti/util/identities.go index 2414d9362..f36f38c4b 100644 --- a/ziti/util/identities.go +++ b/ziti/util/identities.go @@ -247,7 +247,11 @@ func LoadSelectedIdentity() (RestClientIdentity, error) { id := config.GetIdentity() clientIdentity, found := config.EdgeIdentities[id] if !found { - return nil, errors.Errorf("no identity '%v' found in cli config %v", id, configFile) + if len(config.EdgeIdentities) == 0 { + return nil, errors.New("no identities found in CLI config. Please log in using 'ziti edge login' command") + } else { + return nil, errors.Errorf("no identity '%v' found in CLI config %v. You can select an existing identity using 'ziti edge use '", id, configFile) + } } selectedIdentity = clientIdentity }