refactor(storage): standardize buckets error handling (nodejs-storage migration) by angelcaamal · Pull Request #4256 · GoogleCloudPlatform/nodejs-docs-samples

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands the Node.js samples for Google Cloud Storage, offering developers a rich set of examples for interacting with GCS buckets and objects. The new samples cover a broad spectrum of features, from basic CRUD operations to advanced security and performance configurations, aiming to provide clear and practical guidance for common use cases. The inclusion of new system tests reinforces the quality and accuracy of these examples.

Highlights

  • Comprehensive Node.js Samples for Cloud Storage: This pull request introduces a vast collection of new Node.js samples demonstrating a wide range of Google Cloud Storage functionalities, including bucket and file ACLs, lifecycle management, encryption, HMAC keys, notifications, and advanced transfer operations.
  • Enhanced Error Handling and Migration Focus: The changes are part of a broader effort to standardize error handling within Cloud Storage samples and facilitate migration to updated Node.js client library practices.
  • New System Tests for Robustness: Accompanying the new samples are extensive system tests covering various aspects of bucket and file management, IAM, encryption, and transfer manager functionalities, ensuring the reliability and correctness of the provided examples.
  • Transfer Manager Integration: Several new samples specifically highlight the use of the Transfer Manager for efficient parallel uploads and downloads of multiple files and directories, as well as chunked file transfers.
Changelog
  • storage/README.md
    • Added an auto-generated README file detailing all available Node.js samples for Google Cloud Storage.
  • storage/addBucketConditionalBinding.js
    • Added a new sample to demonstrate adding conditional IAM bindings to a bucket.
  • storage/addBucketDefaultOwnerAcl.js
    • Added a new sample for setting a default owner ACL on a bucket.
  • storage/addBucketIamMember.js
    • Added a new sample to show how to add an IAM member to a bucket.
  • storage/addBucketLabel.js
    • Added a new sample for adding labels to a bucket.
  • storage/addBucketOwnerAcl.js
    • Added a new sample for adding an owner ACL to a bucket.
  • storage/addBucketWebsiteConfiguration.js
    • Added a new sample to configure website settings for a bucket.
  • storage/addFileOwnerAcl.js
    • Added a new sample for adding an owner ACL to a file.
  • storage/bucketMetadata.js
    • Added a new sample to retrieve bucket metadata.
  • storage/changeDefaultStorageClass.js
    • Added a new sample to change a bucket's default storage class.
  • storage/changeFileCSEKToCMEK.js
    • Added a new sample to convert a file's Customer-Supplied Encryption Key (CSEK) to a Customer-Managed Encryption Key (CMEK).
  • storage/composeFile.js
    • Added a new sample to combine multiple files into a single new file.
  • storage/configureBucketCors.js
    • Added a new sample to configure CORS settings for a bucket.
  • storage/configureRetries.js
    • Added a new sample demonstrating how to configure retry options for storage operations.
  • storage/copyFile.js
    • Added a new sample for copying a file.
  • storage/copyOldVersionOfFile.js
    • Added a new sample to copy an old version of a file.
  • storage/createBucketWithDualRegion.js
    • Added a new sample to create a dual-region bucket.
  • storage/createBucketWithHierarchicalNamespace.js
    • Added a new sample to create a bucket with hierarchical namespace enabled.
  • storage/createBucketWithObjectRetention.js
    • Added a new sample to create a bucket with object retention enabled.
  • storage/createBucketWithStorageClassAndLocation.js
    • Added a new sample to create a bucket with a specific storage class and location.
  • storage/createBucketWithTurboReplication.js
    • Added a new sample to create a bucket with Turbo Replication enabled.
  • storage/createNewBucket.js
    • Added a new sample for creating a new bucket.
  • storage/createNotification.js
    • Added a new sample to create bucket notifications.
  • storage/deleteBucket.js
    • Added a new sample for deleting a bucket.
  • storage/deleteFile.js
    • Added a new sample for deleting a file.
  • storage/deleteNotification.js
    • Added a new sample to delete bucket notifications.
  • storage/deleteOldVersionOfFile.js
    • Added a new sample to delete an old version of a file.
  • storage/disableBucketLifecycleManagement.js
    • Added a new sample to disable bucket lifecycle management.
  • storage/disableBucketVersioning.js
    • Added a new sample to disable bucket versioning.
  • storage/disableDefaultEventBasedHold.js
    • Added a new sample to disable default event-based holds on a bucket.
  • storage/disableRequesterPays.js
    • Added a new sample to disable requester pays for a bucket.
  • storage/disableSoftDelete.js
    • Added a new sample to disable soft delete policy for a bucket.
  • storage/disableUniformBucketLevelAccess.js
    • Added a new sample to disable uniform bucket-level access.
  • storage/downloadByteRange.js
    • Added a new sample to download a specific byte range of a file.
  • storage/downloadEncryptedFile.js
    • Added a new sample to download an encrypted file.
  • storage/downloadFile.js
    • Added a new sample for downloading a file.
  • storage/downloadFileInChunksWithTransferManager.js
    • Added a new sample to download a file in chunks using Transfer Manager.
  • storage/downloadFileUsingRequesterPays.js
    • Added a new sample to download a file using requester pays.
  • storage/downloadFolderWithTransferManager.js
    • Added a new sample to download a folder using Transfer Manager.
  • storage/downloadIntoMemory.js
    • Added a new sample to download a file's contents directly into memory.
  • storage/downloadManyFilesWithTransferManager.js
    • Added a new sample to download multiple files using Transfer Manager.
  • storage/downloadPublicFile.js
    • Added a new sample to download a publicly accessible file.
  • storage/enableBucketLifecycleManagement.js
    • Added a new sample to enable bucket lifecycle management.
  • storage/enableBucketVersioning.js
    • Added a new sample to enable bucket versioning.
  • storage/enableDefaultEventBasedHold.js
    • Added a new sample to enable default event-based holds on a bucket.
  • storage/enableDefaultKMSKey.js
    • Added a new sample to enable a default KMS key for a bucket.
  • storage/enableRequesterPays.js
    • Added a new sample to enable requester pays for a bucket.
  • storage/enableUniformBucketLevelAccess.js
    • Added a new sample to enable uniform bucket-level access.
  • storage/fileChangeStorageClass.js
    • Added a new sample to change a file's storage class.
  • storage/fileSetMetadata.js
    • Added a new sample to set metadata for a file.
  • storage/generateEncryptionKey.js
    • Added a new sample to generate an encryption key.
  • storage/generateSignedUrl.js
    • Added a new sample to generate a V2 signed URL for a file.
  • storage/generateV4ReadSignedUrl.js
    • Added a new sample to generate a V4 signed URL for reading a file.
  • storage/generateV4SignedPolicy.js
    • Added a new sample to generate a V4 signed policy for uploading files via HTML forms.
  • storage/generateV4UploadSignedUrl.js
    • Added a new sample to generate a V4 signed URL for uploading a file.
  • storage/getAutoclass.js
    • Added a new sample to retrieve autoclass settings for a bucket.
  • storage/getDefaultEventBasedHold.js
    • Added a new sample to get the default event-based hold status of a bucket.
  • storage/getMetadata.js
    • Added a new sample to retrieve file metadata.
  • storage/getMetadataNotifications.js
    • Added a new sample to get metadata for bucket notifications.
  • storage/getPublicAccessPrevention.js
    • Added a new sample to get the public access prevention status of a bucket.
  • storage/getRPO.js
    • Added a new sample to get the Recovery Point Objective (RPO) for a bucket.
  • storage/getRequesterPaysStatus.js
    • Added a new sample to get the requester pays status of a bucket.
  • storage/getRetentionPolicy.js
    • Added a new sample to get the retention policy of a bucket.
  • storage/getServiceAccount.js
    • Added a new sample to retrieve the Google Cloud Storage service account email.
  • storage/getSoftDeletePolicy.js
    • Added a new sample to get the soft delete policy of a bucket.
  • storage/getSoftDeletedBucket.js
    • Added a new sample to get a soft-deleted bucket.
  • storage/getUniformBucketLevelAccess.js
    • Added a new sample to get the uniform bucket-level access status of a bucket.
  • storage/hmacKeyActivate.js
    • Added a new sample to activate an HMAC service account key.
  • storage/hmacKeyCreate.js
    • Added a new sample to create an HMAC service account key.
  • storage/hmacKeyDeactivate.js
    • Added a new sample to deactivate an HMAC service account key.
  • storage/hmacKeyDelete.js
    • Added a new sample to delete an HMAC service account key.
  • storage/hmacKeyGet.js
    • Added a new sample to get metadata for an HMAC service account key.
  • storage/hmacKeysList.js
    • Added a new sample to list HMAC service account keys.
  • storage/listBuckets.js
    • Added a new sample to list all buckets.
  • storage/listBucketsPartialSuccess.js
    • Added a new sample to list buckets with partial success handling.
  • storage/listFiles.js
    • Added a new sample to list files in a bucket.
  • storage/listFilesByPrefix.js
    • Added a new sample to list files by a specified prefix.
  • storage/listFilesPaginate.js
    • Added a new sample to list files with pagination.
  • storage/listFilesWithOldVersions.js
    • Added a new sample to list files including their old versions.
  • storage/listNotifications.js
    • Added a new sample to list all bucket notifications.
  • storage/listSoftDeletedBucket.js
    • Added a new sample to list soft-deleted buckets.
  • storage/listSoftDeletedObjectVersions.js
    • Added a new sample to list soft-deleted object versions.
  • storage/listSoftDeletedObjects.js
    • Added a new sample to list soft-deleted objects.
  • storage/lockRetentionPolicy.js
    • Added a new sample to lock a bucket's retention policy.
  • storage/makeBucketPublic.js
    • Added a new sample to make a bucket publicly readable.
  • storage/makePublic.js
    • Added a new sample to make a file publicly readable.
  • storage/moveFile.js
    • Added a new sample to move a file within a bucket.
  • storage/moveFileAtomic.js
    • Added a new sample to atomically move a file within a bucket.
  • storage/package.json
    • Updated dependencies to include @google-cloud/pubsub, @google-cloud/storage, node-fetch, uuid, yargs, chai, mocha, and p-limit.
  • storage/printBucketAcl.js
    • Added a new sample to print the ACL for a bucket.
  • storage/printBucketAclForUser.js
    • Added a new sample to print a specific user's ACL for a bucket.
  • storage/printFileAcl.js
    • Added a new sample to print the ACL for a file.
  • storage/printFileAclForUser.js
    • Added a new sample to print a specific user's ACL for a file.
  • storage/quickstart.js
    • Added a new quickstart sample for Google Cloud Storage.
  • storage/releaseEventBasedHold.js
    • Added a new sample to release an event-based hold on a file.
  • storage/releaseTemporaryHold.js
    • Added a new sample to release a temporary hold on a file.
  • storage/removeBucketConditionalBinding.js
    • Added a new sample to remove conditional IAM bindings from a bucket.
  • storage/removeBucketCors.js
    • Added a new sample to remove CORS configuration from a bucket.
  • storage/removeBucketDefaultOwner.js
    • Added a new sample to remove a default owner from a bucket's ACL.
  • storage/removeBucketIamMember.js
    • Added a new sample to remove an IAM member from a bucket.
  • storage/removeBucketLabel.js
    • Added a new sample to remove labels from a bucket.
  • storage/removeBucketOwnerAcl.js
    • Added a new sample to remove an owner from a bucket's ACL.
  • storage/removeDefaultKMSKey.js
    • Added a new sample to remove a default KMS key from a bucket.
  • storage/removeFileOwnerAcl.js
    • Added a new sample to remove an owner from a file's ACL.
  • storage/removeRetentionPolicy.js
    • Added a new sample to remove a bucket's retention policy.
  • storage/renameFile.js
    • Added a new sample to rename a file.
  • storage/resources/.gitignore
    • Added a gitignore file to exclude downloaded test files.
  • storage/resources/resourcesSub1/testSub1.txt
    • Added a sample text file for testing directory uploads.
  • storage/resources/test.txt
    • Added a sample text file for various file operations.
  • storage/resources/test2.txt
    • Added another sample text file for various file operations.
  • storage/restoreSoftDeletedBucket.js
    • Added a new sample to restore a soft-deleted bucket.
  • storage/restoreSoftDeletedObject.js
    • Added a new sample to restore a soft-deleted object.
  • storage/rotateEncryptionKey.js
    • Added a new sample to rotate a file's encryption key.
  • storage/scripts/cleanup
    • Added a script to clean up storage buckets created during tests.
  • storage/setAutoclass.js
    • Added a new sample to set autoclass settings for a bucket.
  • storage/setClientEndpoint.js
    • Added a new sample to set a custom client endpoint for Storage operations.
  • storage/setEventBasedHold.js
    • Added a new sample to set an event-based hold on a file.
  • storage/setObjectRetentionPolicy.js
    • Added a new sample to set the object retention policy for a file.
  • storage/setPublicAccessPreventionEnforced.js
    • Added a new sample to enforce public access prevention for a bucket.
  • storage/setPublicAccessPreventionInherited.js
    • Added a new sample to set public access prevention to inherited for a bucket.
  • storage/setRPOAsyncTurbo.js
    • Added a new sample to set Recovery Point Objective (RPO) to ASYNC_TURBO for a bucket.
  • storage/setRPODefault.js
    • Added a new sample to set Recovery Point Objective (RPO) to DEFAULT for a bucket.
  • storage/setRetentionPolicy.js
    • Added a new sample to set a retention policy for a bucket.
  • storage/setSoftDeletePolicy.js
    • Added a new sample to set a soft delete policy for a bucket.
  • storage/setTemporaryHold.js
    • Added a new sample to set a temporary hold on a file.
  • storage/streamFileDownload.js
    • Added a new sample to stream file downloads.
  • storage/streamFileUpload.js
    • Added a new sample to stream file uploads.
  • storage/system-test/acl.test.js
    • Added system tests for ACL operations.
  • storage/system-test/bucketLifecycle.test.js
    • Added system tests for bucket lifecycle management.
  • storage/system-test/bucketLock.test.js
    • Added system tests for bucket lock operations.
  • storage/system-test/buckets.test.js
    • Added system tests for various bucket operations.
  • storage/system-test/encryption.test.js
    • Added system tests for encryption-related operations.
  • storage/system-test/files.test.js
    • Added system tests for file operations.
  • storage/system-test/hmacKey.test.js
    • Added system tests for HMAC key management.
  • storage/system-test/iam.test.js
    • Added system tests for IAM operations.
  • storage/system-test/notifications.test.js
    • Added system tests for bucket notifications.
  • storage/system-test/quickstart.test.js
    • Added system tests for the quickstart sample.
  • storage/system-test/requesterPays.test.js
    • Added system tests for requester pays functionality.
  • storage/system-test/storage.test.js
    • Added system tests for general storage client functionality.
  • storage/system-test/transfer-manager.test.js
    • Added system tests for Transfer Manager operations.
  • storage/uploadDirectory.js
    • Added a new sample to upload an entire directory.
  • storage/uploadDirectoryWithTransferManager.js
    • Added a new sample to upload a directory using Transfer Manager.
  • storage/uploadEncryptedFile.js
    • Added a new sample to upload an encrypted file.
  • storage/uploadFile.js
    • Added a new sample for uploading a file.
  • storage/uploadFileInChunksWithTransferManager.js
    • Added a new sample to upload a file in chunks using Transfer Manager.
  • storage/uploadFileWithKmsKey.js
    • Added a new sample to upload a file with a KMS key.
  • storage/uploadFromMemory.js
    • Added a new sample to upload file contents from memory.
  • storage/uploadManyFilesWithTransferManager.js
    • Added a new sample to upload multiple files using Transfer Manager.
  • storage/uploadWithoutAuthentication.js
    • Added a new sample for unauthenticated file uploads.
  • storage/uploadWithoutAuthenticationSignedUrl.js
    • Added a new sample for unauthenticated file uploads using signed URLs.
  • storage/viewBucketIamMembers.js
    • Added a new sample to view IAM members for a bucket.
Activity
  • The pull request is currently marked as 'WIP' (Work In Progress), indicating ongoing development.
  • The author has included a comprehensive checklist in the PR description, tracking progress on tests, linting, CI, and other necessary requirements.
  • The title suggests this PR is part of a larger 'nodejs-storage migration' effort, implying a strategic update to the Node.js storage samples.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.