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

Improve error handling, fix #416 #462

Merged
merged 2 commits into from
Mar 15, 2017

Conversation

concaf
Copy link
Contributor

@concaf concaf commented Mar 1, 2017

No description provided.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 1, 2017
@concaf concaf mentioned this pull request Mar 1, 2017
@concaf concaf force-pushed the improve_error_handling branch 4 times, most recently from 7b0d5e8 to 430e6fc Compare March 6, 2017 13:14
@concaf concaf changed the title [WIP] Improve error handling, fix #416 Improve error handling, fix #416 Mar 7, 2017
@concaf
Copy link
Contributor Author

concaf commented Mar 7, 2017

Phew, got the tests passing.
Up for review, ping @cdrage @kadel

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")
Copy link
Member

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?

Copy link
Member

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?

Copy link
Contributor Author

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.

@cdrage
Copy link
Member

cdrage commented Mar 14, 2017

Good job man! Did a review and the code LGTM 👍

Just need to rebase against master (I updated the vendoring in a different PR)

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
@concaf concaf force-pushed the improve_error_handling branch 3 times, most recently from dc7cf61 to 5eae411 Compare March 15, 2017 09:08
@concaf
Copy link
Contributor Author

concaf commented Mar 15, 2017

@cdrage fixed! :)

pkg/app/app.go Outdated
@@ -35,6 +35,7 @@ import (

"os"

"github.com/fsouza/go-dockerclient/external/github.com/Sirupsen/logrus"
Copy link
Member

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

Copy link
Contributor Author

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.
@concaf
Copy link
Contributor Author

concaf commented Mar 15, 2017

@cdrage fixed.

@cdrage
Copy link
Member

cdrage commented Mar 15, 2017

LGTM! 👍

@cdrage cdrage merged commit 54f1339 into kubernetes:master Mar 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants