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

cmd/horcrux: showStateCmd should check for errors other than os.IsNotExist #89

Open
odeke-em opened this issue Aug 30, 2022 · 1 comment

Comments

@odeke-em
Copy link

This code in here

if _, err := os.Stat(config.HomeDir); os.IsNotExist(err) {
return fmt.Errorf("%s does not exist, initialize config with horcrux config init and try again", config.HomeDir)
}

assumes that the only error ever will be os.IsNotExist but there is a huge variety of errors that can be returned especially in tools like this that can be deployed on containers

Suggestion

Check for other errors if not nil and handle them appropriately like this

switch _, err := os.Stat(config.HomeDir); {
case err == nil:
        // Do nothing here.
case os.IsNotExist(err):
 	return fmt.Errorf("%s does not exist, initialize config with horcrux config init and try again", config.HomeDir) 
default:
        return fmt.Errorf("%w unhandled error", err)
 } 
@jonathanpberger jonathanpberger changed the title cmd/horcrux: showStateCmd only checks for non-existent errors but others could lurk and cause unintelligible results cmd/horcrux: showStateCmd should check for errors other than os.IsNotExist Mar 21, 2023
@jonathanpberger
Copy link

Currently only checks for non-existent errors, but others could lurk and cause unintelligible results

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