-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Changes to exit codes #7602
base: master
Are you sure you want to change the base?
Changes to exit codes #7602
Conversation
30bc97b
to
b79e6da
Compare
b79e6da
to
8eb3cdd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very nice and unifies the bisync error codes nicely.
I think having 1 as uncategorized and 2 as syntax error is much more sensible as the "default" exit code tends to be 1 and hence uncategorized.
if strings.HasPrefix(err.Error(), "unknown command") && selfupdateEnabled { | ||
Root.PrintErrf("You could use '%s selfupdate' to get latest features.\n\n", Root.CommandPath()) | ||
} | ||
log.Fatalf("Fatal error: %v", err) | ||
log.Printf("Fatal error: %v", err) | ||
os.Exit(exitcode.UsageError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ncw What about this part, is it safe (enough) to assume that whatever ends up here should be exit code 2? I.e. whatever not ending up in resolveExitCode or in any other os.Exit (log.Fatalf) elsewhere. I think typically the rclone nonexisting
case must be handled here, but not sure what else. The alternative would be to move the change into the "unknown command" if above, and perhaps extend it if needed, but what do you think?
What is the purpose of this change?
According to rclone documentation, exit code 1 is for "syntax or usage" and 2 is for "not otherwise categorised" errors. However, in current implementation, exit code 2 will never be returned (*with one exception in bisync, see below), and in reality exit code 1 will be used for anything other than the "otherwise categorised" errors - exit code 1 is the default for unsuccessful returns.
There seem to be a more or less convention for exit codes in Linux/shell world, maybe some specifically for bash:
(https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html)
(https://www.redhat.com/sysadmin/exit-codes-demystified)
This PR does the following changes to exit codes from rclone:
rclone copy a
,rclone copy a b c
orrclone copy --unknownflag a b
.rclone unknowncommand
, or simplyrclone
, this now returns exit code 2 instead of 1.* bisync exception: There was actually one case of exit code 2, in bisync, where it explicitely called
os.Exit
without going throughresolveExitCode
. I added a commit to change that to exit code 7, more in-line with rest of rclone, and updated the description of exit codes in bisync documentation according to these changes affecting exit codes 1, 2 and 7.Was the change discussed in an issue or in the forum before?
https://forum.rclone.org/t/minor-bug-return-code-from-rclone-check/44236
Checklist