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

usability: Handle Exceptions for no resources #103

Merged
merged 4 commits into from
Sep 6, 2021

Conversation

Abhishek-kumar09
Copy link
Contributor

Signed-off-by: Abhishek-kumar09 abhimait1909@gmail.com

Fixes #56

Now empty resource lists are handled by the openebsctl for storage, volumes and bd. They are handled separately on the basis of resourceType, casType and Namespaces.

Screenshot from 2021-09-05 22-10-34

@codecov-commenter
Copy link

Codecov Report

Merging #103 (05678a0) into develop (bcb6cf2) will decrease coverage by 0.45%.
The diff coverage is 38.23%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #103      +/-   ##
===========================================
- Coverage    67.66%   67.20%   -0.46%     
===========================================
  Files           22       22              
  Lines         1633     1662      +29     
===========================================
+ Hits          1105     1117      +12     
- Misses         520      535      +15     
- Partials         8       10       +2     
Impacted Files Coverage Δ
pkg/storage/storage.go 0.00% <0.00%> (ø)
pkg/volume/volume.go 12.22% <0.00%> (-0.72%) ⬇️
pkg/blockdevice/blockdevice.go 74.07% <50.00%> (-3.48%) ⬇️
pkg/util/error.go 71.42% <100.00%> (+25.97%) ⬆️

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 bcb6cf2...05678a0. Read the comment docs.

Copy link
Member

@vharsh vharsh left a comment

Choose a reason for hiding this comment

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

Awesome first unit test. 🎉 😺
This is a cool use of a function for writing out errors predictably. PTAL some minor suggestions for the UT.

} else {
// Show the output using cli-runtime
util.TablePrinter(util.BDTreeListColumnDefinations, rows, printers.PrintOptions{Wide: true})
}
Copy link
Member

Choose a reason for hiding this comment

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

Dang, I'm positive golangCI-lint isn't running all the tools now, I'll will create a good-first-issue for the same.

What should have happened if CI was working optimally ?

The build should have ideally failed because we have added GolangCI-lint to our CI, I cannot recall the exact warning text but the functionality won't change even if the else bracket is removed, the tool which does it likely gosimple.

func awesome() {
    ....
    if something {
        return nil, err
    } else {
        return value, nil
    }
} // end of function

can get simplified to

func awesome() {
    ....
    if something {
        return nil, err
    }
    return value
} // end of function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected.

@@ -40,3 +40,16 @@ func CheckErr(err error, handleErr func(string)) {
}
handleErr(err.Error())
}

// Handle Empty Table Error
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Handle Empty Table Error
// HandleEmptyTableError handles errors when a resource or set of resources aren't found

This is a minor linting issue in golang, exported functions must be properly documented as such.
Ref: https://go.dev/blog/godoc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds great, Done

return fmt.Errorf("no %s found in your cluster", resource)
} else if ns != "" && casType != "" {
return fmt.Errorf("no %s %s found in %s namespace", casType, resource, ns)
} else if casType != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Abhinandan has recently written a nice utility function which returns true for valid casTypes. Try to rebase your code against the current origin/develop and you'd likely see that in this package. Use that one for this condition check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

pkg/util/error_test.go Outdated Show resolved Hide resolved
Signed-off-by: Abhishek-kumar09 <abhimait1909@gmail.com>
Signed-off-by: Abhishek-kumar09 <abhimait1909@gmail.com>
Signed-off-by: Abhishek-kumar09 <abhimait1909@gmail.com>
pkg/util/error.go Outdated Show resolved Hide resolved
Copy link
Member

@vharsh vharsh left a comment

Choose a reason for hiding this comment

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

lgtm

@vharsh vharsh merged commit 7143f01 into openebs:develop Sep 6, 2021
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.

usability: message for no resources found
3 participants