infisical icon indicating copy to clipboard operation
infisical copied to clipboard

Improve CLI error handling

Open maidul98 opened this issue 3 years ago • 5 comments

The current error handeling is not comprehensive as there is no way to add a equivalent friendly message from the cause of an error.

For example, here in the login command we check if the user is already logged in. In the method to check if they are logged in, we just retrun the error as is shown https://github.com/Infisical/infisical/blob/22e7137e742a5d2f87aca3a48d89be33f1903ec1/cli/packages/util/credentials.go#L87

This is problematic because at the command level package, we have to guess exactly why the login check failed. It would be much better, if we can add a helpful message from the login check method so that we do not have to guess the exact cause at command package level.

I propose that we add a new Error type like so

type Error struct {
	Err             error
	DebugMessage    string
	FriendlyMessage string
}

This will allow us to add a FriendlyMessage for every error, allowing us to print the exact message we want to show to the end user for any error message. Please ask questions if you need more clarification.

maidul98 avatar Nov 26 '22 13:11 maidul98

If this is available I'll take it

quinton11 avatar Apr 25 '23 09:04 quinton11

The error handling has been improved slightly since. One other thing that will be helpful for users is to see the URLs of the failed calls. This is because sometimes the user doesn't know if their CLI is pointing to the Infisical cloud of self hosted. Did you have other areas of improvement in mind?

maidul98 avatar Apr 25 '23 13:04 maidul98

Well, the only other area I had in mind improvement wise is the uniformness wrt error handling across the packages in the cli. Some sections like the line you linked above just return the error, others use fmt.Errorf. Perhaps for readability sake that could be addressed. Maybe with all using your suggested solution. What do you think?

quinton11 avatar Apr 25 '23 14:04 quinton11

Hi @maidul98

I noticed that this issue regarding improving CLI error handling hasn't been fully addressed yet. I'd like to take on this task and contribute to the project. Could you please provide an update on the current status? Additionally, are there any specific guidelines or areas you would like me to focus on while working on this improvement?

vish198910 avatar Aug 04 '24 17:08 vish198910

Hi @maidul98, any updates on this?

vish198910 avatar Aug 06 '24 11:08 vish198910