Rclone deletefile cmd return exit code 1 when file not found in remote. Why 1 and not exit code 4?

What is the problem you are having with rclone?

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.

rclone v1.60.0-DEV
- os/version: ubuntu 20.04 (64 bit)
- os/kernel: 5.18.10-76051810-generic (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.19
- go/linking: dynamic
- go/tags: none

Which cloud storage system are you using? (eg Google Drive)

Dropbox

The command you were trying to run (eg rclone copy /tmp remote:tmp)

rclone deletefile dropbox:tmp/examplefile.demo -vv --retries 1

We check exit code after command is run:

echo $?
1

The rclone config contents with secrets removed.

[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

Its because rclone doesn't know whether the thing pointed to is a directory or is a file which doesn't exist at this point.

This perhaps isn't ideal - rclone could do another test here I think.

1 Like

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.

Thanks for the answer! Cheers!

If something doesn't exist, you can't make a choice if it's a file or a directory as it doesn't exist so you have to default to a decision.

Nothing twisted as that's really all you can do as you can't know for sure if someone entered a file or a directory since it doesn't exist.

Fair enough. Thank you for clarifying this.

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.

v1.62.0-beta.6760.93d3ae04c on branch master (uploaded in 15-30 mins)

1 Like

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.

Thanks again. Cheers!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.