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
Merged
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 @@ -11,10 +11,12 @@ Changelog for NeoFS Node

### Fixed
- Do not search for tombstones when handling their expiration, use local indexes instead (#2929)
- `defer` func is not skipped in cobra-based programs (#2942)
roman-khimov marked this conversation as resolved.
Show resolved Hide resolved

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

### Removed

Expand Down
28 changes: 28 additions & 0 deletions cmd/internal/cmderr/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cmderr

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

// ExitErr specific error for ExitOnErr function that passes the exit code and error caused.
type ExitErr struct {
carpawell marked this conversation as resolved.
Show resolved Hide resolved
Code int
Cause error
}

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

Check warning on line 15 in cmd/internal/cmderr/errors.go

View check run for this annotation

Codecov / codecov/patch

cmd/internal/cmderr/errors.go#L15

Added line #L15 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 23 in cmd/internal/cmderr/errors.go

View check run for this annotation

Codecov / codecov/patch

cmd/internal/cmderr/errors.go#L19-L23

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

Check warning on line 26 in cmd/internal/cmderr/errors.go

View check run for this annotation

Codecov / codecov/patch

cmd/internal/cmderr/errors.go#L25-L26

Added lines #L25 - L26 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