Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty configuration during create panics the binary, but ideally should output actionable data #8

Open
AbhinavMir opened this issue Feb 6, 2024 · 1 comment

Comments

@AbhinavMir
Copy link

hi! I was trying to set this up and seems like credential resolution panics the binary instead of outputting something like "Empty ~/,harbor/config, please " - the patch for this is rather easy, should I start a PR or is this a candidate for the mentorship program?

Cheers and thanks!
Abhinav.

@JaeAeich
Copy link
Contributor

Hey @AbhinavMir and @Vad1mo.
I was just checking in on the issue, wanted to see if this is an OK solution :) (if so let me know I'll create a PR)
Given the error we can have at this point are regarding config issues it would make sense to exit quitely.

//pkg/utils/credential_store.go

func resolveCredential(credentialName string) (Credential, error) {
	credentialStore, err := readCredentialStore()
	if err != nil {
		return Credential{}, fmt.Errorf("failed to read credential store: %s", err)
	}

...
	if credentialName == "" {
		return Credential{}, fmt.Errorf("current credential name not set, please login again")
	}
...
	return Credential{}, fmt.Errorf("no credential found for the name: %s, please login again with the credential name: %s", credentialName, credentialName)
}

//pkg/utils/utils.go
func GetClientByCredentialName(credentialName string) *v2client.HarborAPI {
	credential, err := resolveCredential(credentialName)
	if err != nil {
		fmt.Print(err) // If error come from resolveCredential, it make sense to exist and print the user friendly message.
		os.Exit(1)
	}
...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants