mirror of
https://github.com/rclone/rclone.git
synced 2024-11-07 09:04:52 +01:00
cmd: Move exit status codes to separate package
Signal handling by the `atexit` package needs acceess to `exitCodeUncategorizedError`. With this change all exit status values are moved to a dedicated package so that they can be reused. Signed-off-by: Michael Hanselmann <public@hansmi.ch>
This commit is contained in:
parent
ba5c559fec
commit
cf19073ac9
34
cmd/cmd.go
34
cmd/cmd.go
@ -37,6 +37,7 @@ import (
|
||||
"github.com/rclone/rclone/fs/rc/rcserver"
|
||||
"github.com/rclone/rclone/lib/atexit"
|
||||
"github.com/rclone/rclone/lib/buildinfo"
|
||||
"github.com/rclone/rclone/lib/exitcode"
|
||||
"github.com/rclone/rclone/lib/random"
|
||||
"github.com/rclone/rclone/lib/terminal"
|
||||
"github.com/spf13/cobra"
|
||||
@ -60,19 +61,6 @@ var (
|
||||
errorTooManyArguments = errors.New("too many arguments")
|
||||
)
|
||||
|
||||
const (
|
||||
exitCodeSuccess = iota
|
||||
exitCodeUsageError
|
||||
exitCodeUncategorizedError
|
||||
exitCodeDirNotFound
|
||||
exitCodeFileNotFound
|
||||
exitCodeRetryError
|
||||
exitCodeNoRetryError
|
||||
exitCodeFatalError
|
||||
exitCodeTransferExceeded
|
||||
exitCodeNoFilesTransferred
|
||||
)
|
||||
|
||||
// ShowVersion prints the version to stdout
|
||||
func ShowVersion() {
|
||||
osVersion, osKernel := buildinfo.GetOSVersion()
|
||||
@ -484,31 +472,31 @@ func resolveExitCode(err error) {
|
||||
if err == nil {
|
||||
if ci.ErrorOnNoTransfer {
|
||||
if accounting.GlobalStats().GetTransfers() == 0 {
|
||||
os.Exit(exitCodeNoFilesTransferred)
|
||||
os.Exit(exitcode.NoFilesTransferred)
|
||||
}
|
||||
}
|
||||
os.Exit(exitCodeSuccess)
|
||||
os.Exit(exitcode.Success)
|
||||
}
|
||||
|
||||
_, unwrapped := fserrors.Cause(err)
|
||||
|
||||
switch {
|
||||
case unwrapped == fs.ErrorDirNotFound:
|
||||
os.Exit(exitCodeDirNotFound)
|
||||
os.Exit(exitcode.DirNotFound)
|
||||
case unwrapped == fs.ErrorObjectNotFound:
|
||||
os.Exit(exitCodeFileNotFound)
|
||||
os.Exit(exitcode.FileNotFound)
|
||||
case unwrapped == errorUncategorized:
|
||||
os.Exit(exitCodeUncategorizedError)
|
||||
os.Exit(exitcode.UncategorizedError)
|
||||
case unwrapped == accounting.ErrorMaxTransferLimitReached:
|
||||
os.Exit(exitCodeTransferExceeded)
|
||||
os.Exit(exitcode.TransferExceeded)
|
||||
case fserrors.ShouldRetry(err):
|
||||
os.Exit(exitCodeRetryError)
|
||||
os.Exit(exitcode.RetryError)
|
||||
case fserrors.IsNoRetryError(err):
|
||||
os.Exit(exitCodeNoRetryError)
|
||||
os.Exit(exitcode.NoRetryError)
|
||||
case fserrors.IsFatalError(err):
|
||||
os.Exit(exitCodeFatalError)
|
||||
os.Exit(exitcode.FatalError)
|
||||
default:
|
||||
os.Exit(exitCodeUsageError)
|
||||
os.Exit(exitcode.UsageError)
|
||||
}
|
||||
}
|
||||
|
||||
|
25
lib/exitcode/exitcode.go
Normal file
25
lib/exitcode/exitcode.go
Normal file
@ -0,0 +1,25 @@
|
||||
// Package exitcode exports rclone's exit status numbers.
|
||||
package exitcode
|
||||
|
||||
const (
|
||||
// Success is returned when rclone finished without error.
|
||||
Success = iota
|
||||
// UsageError is returned when there was a syntax or usage error in the arguments.
|
||||
UsageError
|
||||
// UncategorizedError is returned for any error not categorised otherwise.
|
||||
UncategorizedError
|
||||
// DirNotFound is returned when a source or destination directory is not found.
|
||||
DirNotFound
|
||||
// FileNotFound is returned when a source or destination file is not found.
|
||||
FileNotFound
|
||||
// RetryError is returned for temporary errors during operations which may be retried.
|
||||
RetryError
|
||||
// NoRetryError is returned for errors from operations which can't/shouldn't be retried.
|
||||
NoRetryError
|
||||
// FatalError is returned for errors one or more retries won't resolve.
|
||||
FatalError
|
||||
// TransferExceeded is returned when network I/O exceeded the quota.
|
||||
TransferExceeded
|
||||
// NoFilesTransferred everything succeeded, but no transfer was made.
|
||||
NoFilesTransferred
|
||||
)
|
Loading…
Reference in New Issue
Block a user