Skip to content

storage: better documentation of error values and types #1865

@f2prateek

Description

@f2prateek

I don't think the client library is wrapping oauth errors into a googleapi.Error.

Client

Storage

Environment

ECS Service on AWS

Code

package main

func main() {
        bucket := "..."
        path := "..."
        r := bytes.NewReader("...")

	w := s.Bucket(bucket).Object(path).NewWriter(ctx)
	w.ContentType = "application/gzip"
        = io.Copy(w, in.Body)

	if err = w.Close(); err != nil {
		var gErr *googleapi.Error
		if errors.As(err, &gErr) {
			if gErr.Code >= 400 && gErr.Code <= 499 {
				fmt.Println("client error") 
			} else {
 				panic(err)
                        }
		} else {
                        panic(err)
                }
	}
}

Expected behavior

I think ideally this should be wrapped into a googleapi.Error. Or at least, the other potential error types could be better documented.

https://pkg.go.dev/cloud.google.com/go/storage?tab=doc

Errors returned by this client are often of the type [`googleapi.Error`](https://godoc.org/google.golang.org/api/googleapi#Error). These errors can be introspected for more information by type asserting to the richer `googleapi.Error` type. For example:

if e, ok := err.(*googleapi.Error); ok {
	  if e.Code == 409 { ... }
}

Actual behavior

The error returned is not wrapped into a googleapi.Error.

oauth2: cannot fetch token: 400 Bad Request
Response: {"error":"invalid_grant","error_description":"Invalid JWT: iss field missing."}

Screenshots

N/A

Additional context

N/A

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the Cloud Storage API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions