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.

file download mutates options arguments #2667

@gnekich

Description

@gnekich

Please make sure you have searched for information in the following guides.

A screenshot that you have tested with "Try this API".

The issue is client side, not in the API
Image

Link to the code that reproduces this issue. A link to a public Github Repository or gist with a minimal reproduction.

delete options.destination;

A step-by-step description of how to reproduce the issue, based on the linked reproduction.

The options object argument in the download method is mutated after use of the function.

import { Storage } from "@google-cloud/storage";

const storageOptions = {
  keyFilename: process.env.DEV_STORAGE_GOOGLE_APPLICATION_CREDENTIALS,
};

const storage = new Storage(storageOptions);
const options = {
  destination: `./cat.jpg`,
};

console.log(`Image will be downloaded to destination: ${options.destination}`);

try {
  const file = await storage
    .bucket('1337-bucket')
    .file('myDemoKey')
    .download(options); // This downloads the file to the specified destination
} catch (error) {
  console.error('Error downloading file... this is PoC bucket does not exist'); // Doesn't really matter 
}

console.log(`Image downloaded to destination: ${options.destination}`); // <-- This won't work because Google has a nasty bug in @google-cloud/storage ...

This is similar to the closed issue #1891 that I was able to find.

delete options.destination;

A clear and concise description of what the bug is, and what you expected to happen.

Passing object to a function should not have a side effect of removing keys from the options object.
It can cause a lot of issues and bugs down the line.

A clear and concise description WHY you expect this behavior, i.e., was it a recent change, there is documentation that points to this behavior, etc. **

There is no documentation that points to this as it is unintended side-effect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: storageIssues related to the googleapis/nodejs-storage API.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions