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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ Changelog for NeoFS Node
- Expose health status of inner ring via Prometheus (#2934)

### Fixed
- `defer` func is not skipped in cobra-based programs (#2942)
Copy link
Member

Choose a reason for hiding this comment

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

Not sure it makes sense for outside reader, but don't have immediate suggestions either.


### Changed
- `ObjectService`'s `Put` RPC handler caches up to 10K lists of per-object sorted container nodes (#2901)
- When an error is returned, no additional help output is displayed in cobra-based programs (#2942)

### Removed

Expand Down
27 changes: 27 additions & 0 deletions cmd/internal/custom_errors/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package custom_errors
Copy link
Contributor

Choose a reason for hiding this comment

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

not a good choice of pkg name https://go.dev/blog/package-names. I can suggest cmderr


import (
"errors"
"fmt"
"os"
)

type ExitErr struct {
Code int
Cause error
}

func (x ExitErr) Error() string { return x.Cause.Error() }

Check warning on line 14 in cmd/internal/custom_errors/errors.go

View check run for this annotation

Codecov / codecov/patch

cmd/internal/custom_errors/errors.go#L14

Added line #L14 was not covered by tests

// ExitOnErr writes error to os.Stderr and calls os.Exit with passed exit code or by default 1.
// Does nothing if err is nil.
func ExitOnErr(err error) {
if err != nil {
var e ExitErr
if !errors.As(err, &e) {
e.Code = 1

Check warning on line 22 in cmd/internal/custom_errors/errors.go

View check run for this annotation

Codecov / codecov/patch

cmd/internal/custom_errors/errors.go#L18-L22

Added lines #L18 - L22 were not covered by tests
}
fmt.Fprintln(os.Stderr, err)
os.Exit(e.Code)

Check warning on line 25 in cmd/internal/custom_errors/errors.go

View check run for this annotation

Codecov / codecov/patch

cmd/internal/custom_errors/errors.go#L24-L25

Added lines #L24 - L25 were not covered by tests
}
}
5 changes: 3 additions & 2 deletions cmd/neofs-adm/internal/modules/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ var (
Short: "NeoFS Administrative Tool",
Long: `NeoFS Administrative Tool provides functions to setup and
manage NeoFS network deployment.`,
RunE: entryPoint,
SilenceUsage: true,
RunE: entryPoint,
SilenceUsage: true,
SilenceErrors: true,
}

configFlag = "config"
Expand Down
Loading
Loading