Skip to content

samples(storagecontrol): add delete folder recursive sample#4340

Closed
nidhiii-27 wants to merge 1 commit into
mainfrom
add-delete-folder-recursive-sample
Closed

samples(storagecontrol): add delete folder recursive sample#4340
nidhiii-27 wants to merge 1 commit into
mainfrom
add-delete-folder-recursive-sample

Conversation

@nidhiii-27

Copy link
Copy Markdown
Contributor

This PR adds the SDK sample and tests for the hierarchical namespace recursive delete feature, resolving b/521168740.

@nidhiii-27 nidhiii-27 requested review from a team as code owners June 10, 2026 09:11
@snippet-bot

snippet-bot Bot commented Jun 10, 2026

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label Jun 10, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a script to recursively delete folders in Google Cloud Storage using the @google-cloud/storage-control library, along with its corresponding system test. Feedback suggests shortening the generated bucket name in tests to avoid exceeding the 63-character limit, and wrapping the bucket deletion in a try/catch block within the cleanup hook to prevent obscuring setup failures.

Comment on lines +22 to +23
const bucketPrefix = `storage-control-samples-${uuid.v4()}`;
const bucketName = `${bucketPrefix}-a`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The bucket name length is currently 62 characters (storage-control-samples- (24) + uuid.v4() (36) + -a (2)), which is extremely close to the Google Cloud Storage bucket name limit of 63 characters. Any slight increase in the prefix or suffix length in future modifications will cause the tests to fail with an invalid bucket name error. It is safer to use a shorter prefix and avoid unnecessary suffixes.

Suggested change
const bucketPrefix = `storage-control-samples-${uuid.v4()}`;
const bucketName = `${bucketPrefix}-a`;
const bucketName = "gcs-sc-samples-" + uuid.v4();

Comment on lines +43 to +50
after(async () => {
try {
await bucket.deleteFiles({force: true});
} catch (e) {
// ignore
}
await bucket.delete();
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the before hook fails (for example, due to permission or quota issues during bucket creation), the after hook will still run in Mocha. Since bucket.delete() is not wrapped in a try/catch block, it will throw a "Not Found" error when trying to delete a non-existent bucket. This unhandled error in the after hook will obscure the actual failure from the before hook in the test output. Wrapping bucket.delete() in a try/catch block ensures robust cleanup and clearer test failure reports.

  after(async () => {
    try {
      await bucket.deleteFiles({force: true});
    } catch (e) {
      // ignore
    }
    try {
      await bucket.delete();
    } catch (e) {
      // ignore
    }
  });

@angelcaamal angelcaamal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To use const [operation] = await controlClient.deleteFolderRecursive(request); you need to update the @google-cloud/storage-control library to its latest version. The current version in package.json (^0.5.0) does not include this method, which is why the test is failing.

@nidhiii-27

Copy link
Copy Markdown
Contributor Author

Thank you @angelcaamal for helping in figuring out the test failure. This PR was raised as an experiment for a project. Closing this one, I'll soon be raising another PR as part of the same project.

@nidhiii-27 nidhiii-27 closed this Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants