这是indexloc提供的服务,不要输入任何密码
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

nextQuery?: {},
apiResponse?: unknown
apiResponse?: unknown,
unreachable?: string[]
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is going to work. There is an issue with callbacks / promisify where if one of the arguments is null / undefined none of the subsequent parameters will get filled in correctly. If I remember correctly, if nextQuery is null / undefined apiResponse will always be missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a valid concern regarding the positional nature of callback arguments and how utilities like promisify handle sparse (null/undefined) values.

However, based on my testing with the current implementation, we are successfully fetching subsequent parameters, even when nextQuery is null. It seems the underlying promise wrapping or argument handling is either explicitly preserving the position with null values or the consuming code is robust enough to handle the array gaps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another approach would be to group all optional properties into a single object; however, this would result in a breaking change. Please let me know if my understanding is incorrect.

interface BucketMetadata {
    nextQuery?: {};
    apiResponse?: unknown;
    unreachable?: string[];
}

export interface GetBucketsCallbackFixed {
  (
    err: Error | null,
    buckets: Bucket[],
    metadata?: BucketMetadata // All optional data is now combined in one object
  ): void;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any other approaches we can take here besides adding yet another field to the callback? I've never been a fan of how the callbacks were implemented in this library as they generally don't adhere to Node style which should be callback(err, data). Additionally, adding another parameter goes against the style we have generally followed in other places in this library.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can use a union type or a structured object in this case, but the customer would need to make some minor adjustments.

  1. buckets: (Bucket | string)[] // This union type allows the array to contain both Bucket objects and strings.

  2. buckets: BucketData // This uses a structured object.

export interface BucketData {
reachableBuckets: Bucket[];
unreachableBuckets?: string[];
}

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.

3 participants