Skip to content

Conversation

@thiyaguk09
Copy link
Contributor

Description

This change implements the returnPartialSuccess option for the getBuckets (or ListBuckets) method to handle scenarios where the external API returns a successful response but includes an unreachable list of resources.

  • New Option: The boolean parameter returnPartialSuccess is added to the GetBucketsRequest interface.
  • Behavior on true: If returnPartialSuccess is set to true and the API response contains resp.unreachable items, the method will execute the callback successfully (with err: null) and pass the array of unreachable bucket IDs as the fifth argument to the callback function.
  • Existing Behavior Preservation: If the option is false (or not set) and unreachable items are present, the function follows the existing failure flow (or implicitly returns success, depending on the previous behavior).
  • API Payload: The returnPartialSuccess parameter is correctly included in the query string (qs) sent to the API endpoint, as it is a known API parameter.

Impact

This change significantly improves the robustness of the ListBuckets operation. Users can now choose to tolerate minor, non-critical failures (like temporary unavailability of a few regions) and successfully retrieve and process the majority of available buckets, preventing a complete application failure.

Testing

  • Unit Tests: Yes, new unit tests have been added to cover the new logic.
    • New Test Cases: Added tests specifically verifying the 5-argument callback signature when returnPartialSuccess: true is set and the API returns an unreachable array.
    • Coverage: Confirmed correct behavior for full success, full failure, and the two partial success/failure modes.
  • Tests Changed: No existing tests were changed, only new ones were added.
  • Breaking Changes: No breaking changes are necessary for existing users. The fifth callback argument (unreachable) is strictly optional (?) and is only provided when explicitly enabled via the new option.

Additional Information

  • This implementation relies on the established convention of the underlying API returning unreachable resource IDs in the resp.unreachable property on a successful HTTP status code.
  • The use of a 5th argument in the callback (unreachable) was chosen to avoid modifying the primary result type (Bucket[]) and to maintain compatibility with existing consumers who expect the 4-argument signature.

Checklist

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease
  • Appropriate docs were updated
  • Appropriate comments were added, particularly in complex areas or places that require background
  • No new warnings or issues will be generated from this change

Fixes # 🦕

Implements the optional parameter `returnPartialSuccess`.

If set to `true` and the API response contains an `unreachable` array,
the function will return a successful callback (`err: null`) and pass
the `unreachable` array as the 5th argument.

This allows users to process the available buckets without the entire
operation failing on soft errors.
New sample for partial success in ListBuckets
(storage_list_buckets_partial_success)
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: storage Issues related to the googleapis/nodejs-storage API. labels Nov 10, 2025
@thiyaguk09 thiyaguk09 marked this pull request as ready for review November 10, 2025 08:37
@thiyaguk09 thiyaguk09 requested review from a team as code owners November 10, 2025 08:37
@snippet-bot
Copy link

snippet-bot bot commented Nov 10, 2025

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

@generated-files-bot
Copy link

Warning: This pull request is touching the following templated files:

src/bucket.ts Outdated
* that the API failed to retrieve (unreachable) due to partial failure.
* Consumers must check this flag before accessing other properties.
*/
unreachable?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can make this unreachable: boolean. No need for it to be optional as a bucket can only be in 2 states.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As you mentioned, there's no need to declare optional for unreachable, as it can cause some property errors. To fix this, want to initialize unreachable: boolean = false (which may show a warning) or simply unreachable = false (which won't show a warning).

src/storage.ts Outdated
const buckets = itemsArray.map((bucket: BucketMetadata) => {
const bucketInstance = this.bucket(bucket.id!);
bucketInstance.metadata = bucket;
bucketInstance.unreachable = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

If you make unreachable not optional, we can remove this as it should default to false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will initialize unreachable = false. This will set the default value to false; otherwise, unreachable would remain undefined here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the googleapis/nodejs-storage API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants