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

cli: Don't print help and don't skip defered funcs on failures #2942

Merged
merged 5 commits into from
Sep 24, 2024

Conversation

End-rey
Copy link
Contributor

@End-rey End-rey commented Sep 19, 2024

Closes #623, #2890.

In neofs-cli I add func common.WrapError that wrap error to custom_errors.ExitErr and return it on every error, But I doubt it. Maybe it is necessary to wrap only the first appearance of this error, or vice versa, only the last one.

Copy link

codecov bot commented Sep 19, 2024

Codecov Report

Attention: Patch coverage is 0% with 1432 lines in your changes missing coverage. Please review.

Project coverage is 23.53%. Comparing base (a0447ce) to head (fc291a2).
Report is 29 commits behind head on master.

Files with missing lines Patch % Lines
cmd/neofs-adm/internal/modules/storagecfg/root.go 0.00% 106 Missing ⚠️
cmd/neofs-cli/modules/object/util.go 0.00% 88 Missing ⚠️
cmd/neofs-cli/modules/object/range.go 0.00% 33 Missing ⚠️
cmd/neofs-cli/modules/container/create.go 0.00% 31 Missing ⚠️
cmd/neofs-cli/modules/container/get.go 0.00% 31 Missing ⚠️
cmd/neofs-cli/modules/control/shards_set_mode.go 0.00% 31 Missing ⚠️
cmd/neofs-cli/modules/object/hash.go 0.00% 31 Missing ⚠️
cmd/neofs-cli/modules/storagegroup/put.go 0.00% 31 Missing ⚠️
cmd/neofs-cli/modules/object/put.go 0.00% 30 Missing ⚠️
cmd/neofs-cli/modules/container/set_eacl.go 0.00% 29 Missing ⚠️
... and 79 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2942      +/-   ##
==========================================
- Coverage   23.88%   23.53%   -0.35%     
==========================================
  Files         776      776              
  Lines       45893    46565     +672     
==========================================
- Hits        10961    10960       -1     
- Misses      34070    34743     +673     
  Partials      862      862              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@End-rey End-rey force-pushed the 623-do-not-print-help-on-any-failure branch from 85bf87d to 24ab511 Compare September 19, 2024 08:54
Copy link
Member

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

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

Conflicts, rebase pls. But looks nice in general. Probably we can add some tests for it as well.

cmd/neofs-cli/internal/common/exit.go Outdated Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
Copy link
Contributor

@cthulhu-rider cthulhu-rider left a comment

Choose a reason for hiding this comment

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

in total, lux gut

afaik #623 can be resolved purely independent, so its better to dedicate a separate small (last) commit for it to not mix with heavy #2890.

also tag intermediate commits with Refs #2890.

cmd/internal/custom_errors/errors.go Outdated Show resolved Hide resolved
cmd/neofs-adm/internal/modules/storagecfg/root.go Outdated Show resolved Hide resolved
cmd/neofs-cli/internal/common/exit.go Outdated Show resolved Hide resolved
cmd/neofs-cli/internal/client/sdk.go Outdated Show resolved Hide resolved
cmd/neofs-cli/internal/common/exit.go Outdated Show resolved Hide resolved
cmd/neofs-cli/internal/common/eacl.go Outdated Show resolved Hide resolved
cmd/neofs-lens/internal/meta/get.go Outdated Show resolved Hide resolved
@End-rey End-rey marked this pull request as draft September 20, 2024 07:02
@End-rey End-rey force-pushed the 623-do-not-print-help-on-any-failure branch 2 times, most recently from b99e708 to 23c2dce Compare September 23, 2024 16:05
@End-rey End-rey marked this pull request as ready for review September 23, 2024 16:17
@End-rey
Copy link
Contributor Author

End-rey commented Sep 23, 2024

Now, in the neofs-cli, func common.WrapError is used after receiving the cobra command error in main.

Copy link
Contributor

@cthulhu-rider cthulhu-rider left a comment

Choose a reason for hiding this comment

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

still suggest to ref first 3 commits to #2890 #2942 (review)

For all cobra-based programs add custom error with code and cause of error and
exit func from programs.

Refs #2890.

Signed-off-by: Andrey Butusov <[email protected]>
Use `RunE` instead of `Run` and throw an error to main function. Then handle
error with custom error handler.

Refs #2890.

Signed-off-by: Andrey Butusov <[email protected]>
@End-rey End-rey force-pushed the 623-do-not-print-help-on-any-failure branch from 23c2dce to 0162cb0 Compare September 24, 2024 09:47
cmd/neofs-lens/internal/writecache/get.go Outdated Show resolved Hide resolved
cmd/neofs-lens/internal/writecache/get.go Outdated Show resolved Hide resolved
cmd/neofs-cli/modules/container/get.go Outdated Show resolved Hide resolved
cmd/neofs-cli/modules/container/nodes.go Outdated Show resolved Hide resolved
cmd/neofs-cli/modules/object/hash.go Outdated Show resolved Hide resolved
cmd/neofs-cli/modules/object/head.go Outdated Show resolved Hide resolved
cmd/neofs-cli/modules/object/range.go Outdated Show resolved Hide resolved
Use `RunE` instead of `Run` and throw an error to main function. Wrap error with
`common.WrapError` to specify the status code. Then handle error with custom
error handler.

Refs #2890.

Signed-off-by: Andrey Butusov <[email protected]>
Use `RunE` instead of `Run` and throw an error to main function. Then handle
error with custom error handler.
Update CHANGELOG.md.

Closes #2890.

Signed-off-by: Andrey Butusov <[email protected]>
@End-rey End-rey force-pushed the 623-do-not-print-help-on-any-failure branch from 0162cb0 to fc291a2 Compare September 24, 2024 14:57
@roman-khimov roman-khimov merged commit b309c2c into master Sep 24, 2024
19 of 21 checks passed
@roman-khimov roman-khimov deleted the 623-do-not-print-help-on-any-failure branch September 24, 2024 19:34
End-rey added a commit that referenced this pull request Sep 25, 2024
From #2942, error format in `adm` is broken. All errors need to be wrapped up:
`fmt.Errorf("Error: %w\n", err)`.

Signed-off-by: Andrey Butusov <[email protected]>
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.

cli: Do not print help on any failure
4 participants