Update dependencies

This commit is contained in:
Ciprian Hacman
2025-08-10 07:59:08 +03:00
parent dea6d70d46
commit ffaefd99ac
289 changed files with 22660 additions and 13039 deletions

View File

@@ -1,3 +1,3 @@
{
"v2": "2.14.1"
"v2": "2.15.0"
}

View File

@@ -1,5 +1,19 @@
# Changelog
## [2.15.0](https://github.com/googleapis/gax-go/compare/v2.14.2...v2.15.0) (2025-07-09)
### Features
* **apierror:** improve gRPC status code mapping for HTTP errors ([#431](https://github.com/googleapis/gax-go/issues/431)) ([c207f2a](https://github.com/googleapis/gax-go/commit/c207f2a19ab91d3baee458b57d4aa992519025c7))
## [2.14.2](https://github.com/googleapis/gax-go/compare/v2.14.1...v2.14.2) (2025-05-12)
### Documentation
* **v2:** Fix Backoff doc to accurately explain Multiplier ([#423](https://github.com/googleapis/gax-go/issues/423)) ([16d1791](https://github.com/googleapis/gax-go/commit/16d17917121ea9f5d84ba52b5c7c7f2ec0f9e784)), refs [#422](https://github.com/googleapis/gax-go/issues/422)
## [2.14.1](https://github.com/googleapis/gax-go/compare/v2.14.0...v2.14.1) (2024-12-19)

View File

@@ -38,6 +38,7 @@ package apierror
import (
"errors"
"fmt"
"net/http"
"strings"
jsonerror "github.com/googleapis/gax-go/v2/apierror/internal/proto"
@@ -49,6 +50,39 @@ import (
"google.golang.org/protobuf/proto"
)
// canonicalMap maps HTTP codes to gRPC status code equivalents.
var canonicalMap = map[int]codes.Code{
http.StatusOK: codes.OK,
http.StatusBadRequest: codes.InvalidArgument,
http.StatusForbidden: codes.PermissionDenied,
http.StatusNotFound: codes.NotFound,
http.StatusConflict: codes.Aborted,
http.StatusRequestedRangeNotSatisfiable: codes.OutOfRange,
http.StatusTooManyRequests: codes.ResourceExhausted,
http.StatusGatewayTimeout: codes.DeadlineExceeded,
http.StatusNotImplemented: codes.Unimplemented,
http.StatusServiceUnavailable: codes.Unavailable,
http.StatusUnauthorized: codes.Unauthenticated,
}
// toCode maps an http code to the most correct equivalent.
func toCode(httpCode int) codes.Code {
if sCode, ok := canonicalMap[httpCode]; ok {
return sCode
}
switch {
case httpCode >= 200 && httpCode < 300:
return codes.OK
case httpCode >= 400 && httpCode < 500:
return codes.FailedPrecondition
case httpCode >= 500 && httpCode < 600:
return codes.Internal
}
return codes.Unknown
}
// ErrDetails holds the google/rpc/error_details.proto messages.
type ErrDetails struct {
ErrorInfo *errdetails.ErrorInfo
@@ -217,6 +251,11 @@ func (a *APIError) Error() string {
// GRPCStatus extracts the underlying gRPC Status error.
// This method is necessary to fulfill the interface
// described in https://pkg.go.dev/google.golang.org/grpc/status#FromError.
//
// For errors that originated as an HTTP-based googleapi.Error, GRPCStatus()
// returns a status that attempts to map from the original HTTP code to an
// equivalent gRPC status code. For use cases where you want to avoid this
// behavior, error unwrapping can be used.
func (a *APIError) GRPCStatus() *status.Status {
return a.status
}
@@ -243,9 +282,9 @@ func (a *APIError) Metadata() map[string]string {
// setDetailsFromError parses a Status error or a googleapi.Error
// and sets status and details or httpErr and details, respectively.
// It returns false if neither Status nor googleapi.Error can be parsed.
// When err is a googleapi.Error, the status of the returned error will
// be set to an Unknown error, rather than nil, since a nil code is
// interpreted as OK in the gRPC status package.
//
// When err is a googleapi.Error, the status of the returned error will be
// mapped to the closest equivalent gGRPC status code.
func (a *APIError) setDetailsFromError(err error) bool {
st, isStatus := status.FromError(err)
var herr *googleapi.Error
@@ -258,7 +297,7 @@ func (a *APIError) setDetailsFromError(err error) bool {
case isHTTPErr:
a.httpErr = herr
a.details = parseHTTPDetails(herr)
a.status = status.New(codes.Unknown, herr.Message)
a.status = status.New(toCode(a.httpErr.Code), herr.Message)
default:
return false
}

View File

@@ -156,10 +156,13 @@ func (r *httpRetryer) Retry(err error) (time.Duration, bool) {
return 0, false
}
// Backoff implements exponential backoff. The wait time between retries is a
// random value between 0 and the "retry period" - the time between retries. The
// retry period starts at Initial and increases by the factor of Multiplier
// every retry, but is capped at Max.
// Backoff implements backoff logic for retries. The configuration for retries
// is described in https://google.aip.dev/client-libraries/4221. The current
// retry limit starts at Initial and increases by a factor of Multiplier every
// retry, but is capped at Max. The actual wait time between retries is a
// random value between 1ns and the current retry limit. The purpose of this
// random jitter is explained in
// https://www.awsarchitectureblog.com/2015/03/backoff.html.
//
// Note: MaxNumRetries / RPCDeadline is specifically not provided. These should
// be built on top of Backoff.

View File

@@ -30,4 +30,4 @@
package internal
// Version is the current tagged release of the library.
const Version = "2.14.1"
const Version = "2.15.0"

View File

@@ -0,0 +1,88 @@
// Copyright 2024, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Package grpclog in intended for internal use by generated clients only.
package grpclog
import (
"context"
"encoding/json"
"log/slog"
"strings"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
)
// ProtoMessageRequest returns a lazily evaluated [slog.LogValuer] for
// the provided message. The context is used to extract outgoing headers.
func ProtoMessageRequest(ctx context.Context, msg proto.Message) slog.LogValuer {
return &protoMessage{ctx: ctx, msg: msg}
}
// ProtoMessageResponse returns a lazily evaluated [slog.LogValuer] for
// the provided message.
func ProtoMessageResponse(msg proto.Message) slog.LogValuer {
return &protoMessage{msg: msg}
}
type protoMessage struct {
ctx context.Context
msg proto.Message
}
func (m *protoMessage) LogValue() slog.Value {
if m == nil || m.msg == nil {
return slog.Value{}
}
var groupValueAttrs []slog.Attr
if m.ctx != nil {
var headerAttr []slog.Attr
if m, ok := metadata.FromOutgoingContext(m.ctx); ok {
for k, v := range m {
headerAttr = append(headerAttr, slog.String(k, strings.Join(v, ",")))
}
}
if len(headerAttr) > 0 {
groupValueAttrs = append(groupValueAttrs, slog.Any("headers", headerAttr))
}
}
mo := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
if b, err := mo.Marshal(m.msg); err == nil {
var m map[string]any
if err := json.Unmarshal(b, &m); err == nil {
groupValueAttrs = append(groupValueAttrs, slog.Any("payload", m))
}
}
return slog.GroupValue(groupValueAttrs...)
}

View File

@@ -0,0 +1,63 @@
// Copyright 2024, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//go:build go1.23
// Package iterator contains helper for working with iterators. It is meant for
// internal use only by the Go Client Libraries.
package iterator
import (
"iter"
otherit "google.golang.org/api/iterator"
)
// RangeAdapter transforms client iterator type into a [iter.Seq2] that can
// be used with Go's range expressions.
//
// This is for internal use only.
func RangeAdapter[T any](next func() (T, error)) iter.Seq2[T, error] {
var err error
return func(yield func(T, error) bool) {
for {
if err != nil {
return
}
var resp T
resp, err = next()
if err == otherit.Done {
return
}
if !yield(resp, err) {
return
}
}
}
}