mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 04:04:46 +08:00
cmd: change exit code from 1 to 2 for syntax and usage errors
This commit is contained in:
parent
462a1cf491
commit
a849fd59f0
10
cmd/cmd.go
10
cmd/cmd.go
|
@ -50,7 +50,6 @@ var (
|
||||||
version bool
|
version bool
|
||||||
// Errors
|
// Errors
|
||||||
errorCommandNotFound = errors.New("command not found")
|
errorCommandNotFound = errors.New("command not found")
|
||||||
errorUncategorized = errors.New("uncategorized error")
|
|
||||||
errorNotEnoughArguments = errors.New("not enough arguments")
|
errorNotEnoughArguments = errors.New("not enough arguments")
|
||||||
errorTooManyArguments = errors.New("too many arguments")
|
errorTooManyArguments = errors.New("too many arguments")
|
||||||
)
|
)
|
||||||
|
@ -495,8 +494,6 @@ func resolveExitCode(err error) {
|
||||||
os.Exit(exitcode.DirNotFound)
|
os.Exit(exitcode.DirNotFound)
|
||||||
case errors.Is(err, fs.ErrorObjectNotFound):
|
case errors.Is(err, fs.ErrorObjectNotFound):
|
||||||
os.Exit(exitcode.FileNotFound)
|
os.Exit(exitcode.FileNotFound)
|
||||||
case errors.Is(err, errorUncategorized):
|
|
||||||
os.Exit(exitcode.UncategorizedError)
|
|
||||||
case errors.Is(err, accounting.ErrorMaxTransferLimitReached):
|
case errors.Is(err, accounting.ErrorMaxTransferLimitReached):
|
||||||
os.Exit(exitcode.TransferExceeded)
|
os.Exit(exitcode.TransferExceeded)
|
||||||
case errors.Is(err, fssync.ErrorMaxDurationReached):
|
case errors.Is(err, fssync.ErrorMaxDurationReached):
|
||||||
|
@ -507,8 +504,10 @@ func resolveExitCode(err error) {
|
||||||
os.Exit(exitcode.NoRetryError)
|
os.Exit(exitcode.NoRetryError)
|
||||||
case fserrors.IsFatalError(err):
|
case fserrors.IsFatalError(err):
|
||||||
os.Exit(exitcode.FatalError)
|
os.Exit(exitcode.FatalError)
|
||||||
default:
|
case errors.Is(err, errorCommandNotFound), errors.Is(err, errorNotEnoughArguments), errors.Is(err, errorTooManyArguments):
|
||||||
os.Exit(exitcode.UsageError)
|
os.Exit(exitcode.UsageError)
|
||||||
|
default:
|
||||||
|
os.Exit(exitcode.UncategorizedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,6 +535,7 @@ func Main() {
|
||||||
if strings.HasPrefix(err.Error(), "unknown command") && selfupdateEnabled {
|
if strings.HasPrefix(err.Error(), "unknown command") && selfupdateEnabled {
|
||||||
Root.PrintErrf("You could use '%s selfupdate' to get latest features.\n\n", Root.CommandPath())
|
Root.PrintErrf("You could use '%s selfupdate' to get latest features.\n\n", Root.CommandPath())
|
||||||
}
|
}
|
||||||
fs.Fatalf(nil, "Fatal error: %v", err)
|
fs.Logf(nil, "Fatal error: %v", err)
|
||||||
|
os.Exit(exitcode.UsageError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,7 +174,7 @@ func TestCmdTest(t *testing.T) {
|
||||||
// Test error and error output
|
// Test error and error output
|
||||||
out, err = rclone("version", "--provoke-an-error")
|
out, err = rclone("version", "--provoke-an-error")
|
||||||
if assert.Error(t, err) {
|
if assert.Error(t, err) {
|
||||||
assert.Contains(t, err.Error(), "exit status 1")
|
assert.Contains(t, err.Error(), "exit status 2")
|
||||||
assert.Contains(t, out, "Error: unknown flag")
|
assert.Contains(t, out, "Error: unknown flag")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2868,9 +2868,9 @@ messages may not be valid after the retry. If rclone has done a retry
|
||||||
it will log a high priority message if the retry was successful.
|
it will log a high priority message if the retry was successful.
|
||||||
|
|
||||||
### List of exit codes ###
|
### List of exit codes ###
|
||||||
* `0` - success
|
* `0` - Success
|
||||||
* `1` - Syntax or usage error
|
* `1` - Error not otherwise categorised
|
||||||
* `2` - Error not otherwise categorised
|
* `2` - Syntax or usage error
|
||||||
* `3` - Directory not found
|
* `3` - Directory not found
|
||||||
* `4` - File not found
|
* `4` - File not found
|
||||||
* `5` - Temporary error (one that more retries might fix) (Retry errors)
|
* `5` - Temporary error (one that more retries might fix) (Retry errors)
|
||||||
|
|
|
@ -4,10 +4,10 @@ package exitcode
|
||||||
const (
|
const (
|
||||||
// Success is returned when rclone finished without error.
|
// Success is returned when rclone finished without error.
|
||||||
Success = iota
|
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 is returned for any error not categorised otherwise.
|
||||||
UncategorizedError
|
UncategorizedError
|
||||||
|
// UsageError is returned when there was a syntax or usage error in the arguments.
|
||||||
|
UsageError
|
||||||
// DirNotFound is returned when a source or destination directory is not found.
|
// DirNotFound is returned when a source or destination directory is not found.
|
||||||
DirNotFound
|
DirNotFound
|
||||||
// FileNotFound is returned when a source or destination file is not found.
|
// FileNotFound is returned when a source or destination file is not found.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user