When one tries to delete a file that does not exist in the remote. If one does it with rclone delete the exitcode of the program is 3 (Directory not found). But if one tries it with rclone deletefile then the exitcode is 1 (Syntax or usage error). I'm following the List of rclone exit codes meaning in the documentation
My question is: Why does deletefile fails with exit code 1 instead of 4 (File not found)? Is this the expected behavior?
Thanks in advance for any comments.
Run the command 'rclone version' and share the full output of the command.
[dropbox]
type = dropbox
token = {"access_token":"<secret-here>","token_type":"bearer","refresh_token":"<secret-here>","expiry":"2023-03-01T13:47:10.382308335-06:00"}
A log from the command with the -vv flag
<7>DEBUG : rclone: Version "v1.60.0-DEV" starting with parameters ["/home/alfredo/workspace/rclone_wrapper/gogobox/rclone/rclone" "deletefile" "dropbox:tmp/examplefile.demo" "-vv" "--retries" "1"]
<7>DEBUG : rclone: systemd logging support activated
<7>DEBUG : Creating backend with remote "dropbox:tmp/examplefile.demo"
<7>DEBUG : Using config file from "/home/alfredo/.config/rclone/rclone.conf"
<3>ERROR : Attempt 1/1 failed with 1 errors and: dropbox:tmp/examplefile.demo is a directory or doesn't exist
<7>DEBUG : 6 go routines active
<6>INFO : Dropbox root 'tmp/examplefile.demo': Commiting uploads - please wait...
Failed to deletefile: dropbox:tmp/examplefile.demo is a directory or doesn't exist
So, If I understand you correctly, you explain that if the thing you intent to delete were a directory that would constitute a "Syntax or usage error" because the command applies to files only. Cool, but... If I'm trying to delete a file that happen to be missing, and there is no directory with that same path, I would expect a "File not found" error, not a "Syntax or usage error".
But, if this is the expected behavior then I will live with it.
I decided on further reflection to change the error code for this to error 4. Error 4 will be return if the file isn't found or the path passed in is a directory. However the error message will make that clear and think error 4 is more sensible here.
Thank you, that's amazing! I felt it made more sense to return Error 4, but I did not want to stir the waters too much if this is the expected behavior.
In case it's helpful, my reasoning in support of this change goes as follows:
"File not found" is a true statement whether deletefile:
(case 1) can not find a file under the provided path, or,
(case 2) there was a directory in the provided path.
In both cases a file was not found on that path, true statement! In contrast Error 1 "Syntax or User Error" is only a true statement for case 2, (unless you think that it's the user fault if a file is not found, in which case why having a separate Error 4 in the first place?).
Why I care about this:
I'm doing a little automation script using rclone, my script takes different actions if rclone exits with a "User Error" code than if it exits with "File not found". Basically for my case it's ok if the file was not found (a previous execution failed maybe), but a "User error" signals something very wrong with the logic of my script.
For me, I decided to work around this and use rclone delete instead of rclone deletefile because the first give me the exit code that allows my script to differentiate between: 1. My logic is wrong, or, 2. The object was not found. That's a big difference for automated tools I think.