-
Notifications
You must be signed in to change notification settings - Fork 770
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
Improve error handling, fix #416 #462
Conversation
7b0d5e8
to
430e6fc
Compare
0c9071d
to
24a3ecf
Compare
komposeObject := kobject.KomposeObject{ | ||
ServiceConfigs: make(map[string]kobject.ServiceConfig), | ||
LoadedFrom: "bundle", | ||
} | ||
file := files[0] | ||
buf, err := ioutil.ReadFile(file) | ||
if err != nil { | ||
log.Fatalf("Failed to read bundles file: %s ", err) | ||
return kobject.KomposeObject{}, errors.Wrap(err, "ioutil.ReadFile failed, Failed to read bundles file") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious: Is it good practice to send the method/function name in error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also follow up question here you are using the error message as ioutil.ReadFile
failed which is kinda absolute name but below at line#191 you have just used the name which is loadFile
, why is that so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@surajssd about the good practice part, it's a very subjective opinion, but we can use it to track down the error when the error messages will get printed in app.go
and about the the error message part, I added the name of the failing functions wrt the function they were failing in, so it gets easier to track down the error.
Good job man! Did a review and the code LGTM 👍 Just need to rebase against master (I updated the vendoring in a different PR) |
80a9140
to
7fd2c4a
Compare
This commit refactors the code to remove more or less all occurences of logrus.Fatalf() from the code under pkg/ except for app.go where all the errors are being handled currently. This is being done since random logrus.Fatalf() calls all around the code was making handling the errors, unit testing and troubleshooting a bit more painful. logrus.Fatalf() calls are either replaced by return errors.New("new error") or return errors.Wrap(err, "annonate error") calls, and the function signatures are accordingly changed to accomodate the new return values. The unit tests which previously used to check if logrus.Fatalf() calls worked fine have also been fixed to only check for errors now. Fixes kubernetes#416
dc7cf61
to
5eae411
Compare
@cdrage fixed! :) |
pkg/app/app.go
Outdated
@@ -35,6 +35,7 @@ import ( | |||
|
|||
"os" | |||
|
|||
"github.com/fsouza/go-dockerclient/external/github.com/Sirupsen/logrus" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not import github.com/Sirupsen/logrus instead of from fsouza
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, never realized that logrus
was aliased to log
, so my editor ended up importing this. Fixed! Nice catch, man :)
This adds github.com/pkg/errors to glide.yaml followed by glide and glide-vc commands. The github.com/pkg/errors package is currently required mainly for the errors.Wrap() and errors.New() methods, since this lets us to annotate the errors while passing the error message up the call stack.
5eae411
to
e9544ca
Compare
@cdrage fixed. |
LGTM! 👍 |
No description provided.