vmware-archive / operator-builder

A Kubebuilder plugin to accelerate the development of Kubernetes operators
MIT License
41 stars 6 forks source link

refactor: wrapped errors #240

Open scottd018 opened 2 years ago

scottd018 commented 2 years ago

Define a consistent format for wrapping errors and defining errors.

Some thoughts on how to do this:

Option 1:

return nil, fmt.Errorf("%w; unable to convert resources object to string array", err)
unable to convert workload config spec.resources to []map[string]interface; [map[filename:/path/to/my/child-resources.yaml]]; unable to convert resources object to string array; unable to mutate configuration fields; error adding flags to `init-config collection` subcommand

Option 2:

return nil, fmt.Errorf("%w - unable to convert resources object to string array", err)
unable to convert workload config spec.resources to []map[string]interface - [map[filename:/path/to/my/child-resources.yaml]] - unable to convert resources object to string array - unable to mutate configuration fields; error adding flags to `init-config collection` subcommand

Option 3:

return nil, fmt.Errorf("%w, unable to convert resources object to string array", err)
unable to convert workload config spec.resources to []map[string]interface, [map[filename:/path/to/my/child-resources.yaml]], unable to convert resources object to string array, unable to mutate configuration fields; error adding flags to `init-config collection` subcommand

These obviously aren't the only options but are some of the patterns that I have found.

scottd018 commented 2 years ago

@JefeDavis I think you probably have a strong opinion on the pattern that we should follow, so interested in your suggestions here.

JefeDavis commented 2 years ago

I prefer, fmt.Errorf("Unable to convert slice to string, %w", err)