Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

FR: Add File.delete options property to count missing file as success #1235

@willbattel

Description

@willbattel

Is your feature request related to a problem? Please describe.
I frequently find myself performing delete operations on files that may or may not exist. Similar to how Cloud Firestore's delete operation works, I would like for the Cloud Storage delete operation to consider a non-existent file as a successful deletion. In other words, I want my delete operation to be considered successful if the file does not exist after the operation completes- regardless of if it did exist before the operation.

Describe the solution you'd like
The delete operation (docs here) takes an optional options object, whose only parameter is currently userProject. I would like a new property to be available that I could use to enable this mechanism on a per-operation basis. The syntax might look something like:

await myBucket.file("thisFileMightNotExist.txt").delete({mustExist: false})

Describe alternatives you've considered
The two alternatives are to either 1) run a File.exists operation first, or 2) handle deletion error in catch block. Both alternatives work, they're just not very elegant. Alternative 1 technically also leaves an unlikely but possible scenario where the file is removed after the the exists operation but before the delete operation.

Additional context
None.

Metadata

Metadata

Labels

api: storageIssues related to the googleapis/nodejs-storage API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions