Skip to content

Commit

Permalink
fix(gengapic): remove unknown enum error helper (#1358)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz authored Jun 5, 2023
1 parent 3013a70 commit 34af96c
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 50 deletions.
12 changes: 0 additions & 12 deletions internal/gengapic/doc_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func (g *generator) genDocFile(year int, scopes []string, serv *descriptor.Servi
p("import (")
p("%s%q", "\t", "context")
if hasREST {
p("%s%q", "\t", "fmt")
p("%s%q", "\t", "net/http")
}
p("%s%q", "\t", "runtime")
Expand Down Expand Up @@ -212,17 +211,6 @@ func (g *generator) genDocFile(year int, scopes []string, serv *descriptor.Servi
}

if hasREST {
// UnknownEnum error check helper.
p("// maybeUnknownEnum wraps the given proto-JSON parsing error if it is the result")
p("// of receiving an unknown enum value.")
p("func maybeUnknownEnum(err error) error {")
p(` if strings.Contains(err.Error(), "invalid value for enum type") {`)
p(` err = fmt.Errorf("received an unknown enum value; a later version of the library may support it: %%w", err)`)
p(" }")
p(" return err")
p("}")
p("")

// buildHeaders from context and other metadata helper.
p("// buildHeaders extracts metadata from the outgoing context, joins it with any other")
p("// given metadata, and converts them into a http.Header. ")
Expand Down
6 changes: 3 additions & 3 deletions internal/gengapic/genrest.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ func (g *generator) pagingRESTCall(servName string, m *descriptor.MethodDescript
p(" }")
p("")
p(" if err := unm.Unmarshal(buf, resp); err != nil {")
p(" return maybeUnknownEnum(err)")
p(" return err")
p(" }")
p("")
p(" return nil")
Expand Down Expand Up @@ -970,7 +970,7 @@ func (g *generator) lroRESTCall(servName string, m *descriptor.MethodDescriptorP
p(" }")
p("")
p(" if err := unm.Unmarshal(buf, resp); err != nil {")
p(" return maybeUnknownEnum(err)")
p(" return err")
p(" }")
p("")
p(" return nil")
Expand Down Expand Up @@ -1184,7 +1184,7 @@ func (g *generator) unaryRESTCall(servName string, m *descriptor.MethodDescripto
p("}")
} else {
p("if err := unm.Unmarshal(buf, resp); err != nil {")
p(" return maybeUnknownEnum(err)")
p(" return err")
p("}")
}

Expand Down
10 changes: 0 additions & 10 deletions internal/gengapic/testdata/doc_file.want
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ package awesome // import "path/to/awesome"

import (
"context"
"fmt"
"net/http"
"runtime"
"strings"
Expand Down Expand Up @@ -168,15 +167,6 @@ func versionGo() string {
return "UNKNOWN"
}

// maybeUnknownEnum wraps the given proto-JSON parsing error if it is the result
// of receiving an unknown enum value.
func maybeUnknownEnum(err error) error {
if strings.Contains(err.Error(), "invalid value for enum type") {
err = fmt.Errorf("received an unknown enum value; a later version of the library may support it: %w", err)
}
return err
}

// buildHeaders extracts metadata from the outgoing context, joins it with any other
// given metadata, and converts them into a http.Header.
func buildHeaders(ctx context.Context, mds ...metadata.MD) http.Header {
Expand Down
10 changes: 0 additions & 10 deletions internal/gengapic/testdata/doc_file_alpha.want
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ package awesome // import "path/to/awesome"

import (
"context"
"fmt"
"net/http"
"runtime"
"strings"
Expand Down Expand Up @@ -170,15 +169,6 @@ func versionGo() string {
return "UNKNOWN"
}

// maybeUnknownEnum wraps the given proto-JSON parsing error if it is the result
// of receiving an unknown enum value.
func maybeUnknownEnum(err error) error {
if strings.Contains(err.Error(), "invalid value for enum type") {
err = fmt.Errorf("received an unknown enum value; a later version of the library may support it: %w", err)
}
return err
}

// buildHeaders extracts metadata from the outgoing context, joins it with any other
// given metadata, and converts them into a http.Header.
func buildHeaders(ctx context.Context, mds ...metadata.MD) http.Header {
Expand Down
10 changes: 0 additions & 10 deletions internal/gengapic/testdata/doc_file_beta.want
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ package awesome // import "path/to/awesome"

import (
"context"
"fmt"
"net/http"
"runtime"
"strings"
Expand Down Expand Up @@ -170,15 +169,6 @@ func versionGo() string {
return "UNKNOWN"
}

// maybeUnknownEnum wraps the given proto-JSON parsing error if it is the result
// of receiving an unknown enum value.
func maybeUnknownEnum(err error) error {
if strings.Contains(err.Error(), "invalid value for enum type") {
err = fmt.Errorf("received an unknown enum value; a later version of the library may support it: %w", err)
}
return err
}

// buildHeaders extracts metadata from the outgoing context, joins it with any other
// given metadata, and converts them into a http.Header.
func buildHeaders(ctx context.Context, mds ...metadata.MD) http.Header {
Expand Down
2 changes: 1 addition & 1 deletion internal/gengapic/testdata/rest_CustomOp.want
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (c *fooRESTClient) CustomOp(ctx context.Context, req *foopb.Foo, opts ...ga
}

if err := unm.Unmarshal(buf, resp); err != nil {
return maybeUnknownEnum(err)
return err
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/gengapic/testdata/rest_LongrunningRPC.want
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c *fooRESTClient) LongrunningRPC(ctx context.Context, req *foopb.Foo, opts
}

if err := unm.Unmarshal(buf, resp); err != nil {
return maybeUnknownEnum(err)
return err
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/gengapic/testdata/rest_PagingRPC.want
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c *fooRESTClient) PagingRPC(ctx context.Context, req *foopb.PagedFooReques
}

if err := unm.Unmarshal(buf, resp); err != nil {
return maybeUnknownEnum(err)
return err
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/gengapic/testdata/rest_UnaryRPC.want
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c *fooRESTClient) UnaryRPC(ctx context.Context, req *foopb.Foo, opts ...ga
}

if err := unm.Unmarshal(buf, resp); err != nil {
return maybeUnknownEnum(err)
return err
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/gengapic/testdata/rest_UpdateRPC.want
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (c *fooRESTClient) UpdateRPC(ctx context.Context, req *foopb.UpdateRequest,
}

if err := unm.Unmarshal(buf, resp); err != nil {
return maybeUnknownEnum(err)
return err
}

return nil
Expand Down

0 comments on commit 34af96c

Please sign in to comment.