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

mc heal and mc mirror should respond with exit code (0) incase of errors #2543

Merged
merged 1 commit into from
Sep 20, 2018

Conversation

Praveenrajmani
Copy link
Collaborator

@Praveenrajmani Praveenrajmani commented Sep 18, 2018

mc heal will now respond with proper error on client.Heal
Will also add the fix for mc mirror (#2474)

Tested By

  • ./mc admin heal --debug -r none; echo $?
  • ./mc mirror --quiet foo play/testbucket; echo $?

Fixes #2534
Fixes #2474

@Praveenrajmani Praveenrajmani changed the title [WIP] mc heal should respond with os.exit(0) incase of errors [WIP] mc heal should respond with error code (0) incase of errors Sep 18, 2018
@Praveenrajmani Praveenrajmani changed the title [WIP] mc heal should respond with error code (0) incase of errors [WIP] mc heal should respond with exit code (0) incase of errors Sep 18, 2018
Copy link
Member

@vadmeste vadmeste left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kannappanr
Copy link
Collaborator

@Praveenrajmani Is this still WIP?

@Praveenrajmani
Copy link
Collaborator Author

Yes . i thought of fixing the mc mirror also in the same PR. Need some time for that

@codecov
Copy link

codecov bot commented Sep 19, 2018

Codecov Report

Merging #2543 into master will not change coverage.
The diff coverage is 0%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2543   +/-   ##
=======================================
  Coverage   10.63%   10.63%           
=======================================
  Files         106      106           
  Lines       10703    10703           
=======================================
  Hits         1138     1138           
  Misses       9415     9415           
  Partials      150      150
Impacted Files Coverage Δ
cmd/admin-heal.go 0% <0%> (ø) ⬆️
cmd/typed-errors.go 7.31% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c9f3369...3c0f142. Read the comment docs.

@Praveenrajmani Praveenrajmani changed the title [WIP] mc heal should respond with exit code (0) incase of errors mc heal and mc mirror should respond with exit code (0) incase of errors Sep 19, 2018
@Praveenrajmani
Copy link
Collaborator Author

Done and ready for review

@Praveenrajmani Praveenrajmani force-pushed the zeroerrfix branch 2 times, most recently from e69e385 to 624a074 Compare September 19, 2018 11:46
@kannappanr
Copy link
Collaborator

@poornas @vadmeste please re-review the PR again

@@ -587,6 +591,9 @@ func (mj *mirrorJob) mirror(ctx context.Context, cancelMirror context.CancelFunc
}
}
if err != nil {
if err.ToGoError().Error() == ErrBucketDoNotExist.Error() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Praveenrajmani if you see little below, the code already returns err.Trace() for errors that we don't ignore.

What's happening is that the code is always running case overwriteNotAllowedErr even for bucket is not found error.

The reason is that overwriteNotAllowedErr satisfies error interface that's why that switch case is always executed.

So to avoid this behavior, you can apply the following diff:

diff --git a/cmd/typed-errors.go b/cmd/typed-errors.go
index fd1590e8..50665be4 100644
--- a/cmd/typed-errors.go
+++ b/cmd/typed-errors.go
@@ -96,11 +96,13 @@ var errInvalidTarget = func(URL string) *probe.Error {
        return probe.NewError(invalidTargetErr(errors.New(msg))).Untrace()
 }

-type overwriteNotAllowedErr error
+type overwriteNotAllowedErr struct {
+       error
+}

 var errOverWriteNotAllowed = func(URL string) *probe.Error {
        msg := "Overwrite not allowed for `" + URL + "`. Use `--overwrite` to override this behavior."
-       return probe.NewError(overwriteNotAllowedErr(errors.New(msg)))
+       return probe.NewError(overwriteNotAllowedErr{errors.New(msg)})
 }

 type sourceIsDirErr error

So instead of adding this code, you can modify overwriteNotAllowedErr from interface to structure:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes overwriteNotAllowedErr in switch case acts as default since it is an interface that returns an error , So the idea was to string check.
This seems better though , will change it

Copy link
Member

@vadmeste vadmeste left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small change needed

@@ -587,6 +591,9 @@ func (mj *mirrorJob) mirror(ctx context.Context, cancelMirror context.CancelFunc
}
}
if err != nil {
if err.ToGoError().Error() == ErrBucketDoNotExist.Error() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct style expected style is to avoid string matching instead rely on types.

switch err.ToGoError().(type) {
case BucketDoesNotExist:

Copy link
Collaborator Author

@Praveenrajmani Praveenrajmani Sep 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes will change it to a struct with a error as Anis suggested

@Praveenrajmani
Copy link
Collaborator Author

Changes addressed .. Ready for re-review

Copy link
Member

@vadmeste vadmeste left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kannappanr kannappanr merged commit b2d2e09 into minio:master Sep 20, 2018
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

Successfully merging this pull request may close these issues.

admin heal command returns exit code 0 on errors Mirror command returns exit code 0 on errors
6 participants