Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for legacy errors #78

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Change any of the following values by passing `-option="Value"` CLI flag to `web
| `-json=jsoniter` | `"stdlib"` | use alternative json encoding package | v0.12.0 |
| `-fixEmptyArrays` | `false` | force empty array `[]` instead of `null` in JSON (see Go [#27589][go27589]) | v0.13.0 |
| `-errorStackTrace` | `false` | enables error stack traces | v0.14.0 |
| `-legacyErrors` | `false` | enable legacy errors (v0.10.0 or older) | v0.11.0 |
| `-webrpcHeader` | `true` | enable client send webrpc version in http headers | v0.16.0 |

Example:
Expand Down
93 changes: 1 addition & 92 deletions _examples/golang-basics/example.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions _examples/golang-basics/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,3 @@ func TestGetUser(t *testing.T) {
assert.NoError(t, err)
}
}

func TestLegacyErrors(t *testing.T) {
{
_, err := client.GetUser(context.Background(), nil, 0)
assert.Error(t, err)
assert.ErrorIs(t, err, ErrInvalidArgument)

_, err = client.GetUser(context.Background(), nil, 1000)
assert.Error(t, err)
assert.ErrorIs(t, err, ErrUnavailable)
}
}
15 changes: 3 additions & 12 deletions _examples/golang-basics/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package main

//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=example.ridl -target=../../../gen-golang -pkg=main -server -client -legacyErrors -fixEmptyArrays -out=./example.gen.go
//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=example.ridl -target=../../../gen-golang -pkg=main -server -client -fixEmptyArrays -out=./example.gen.go

import (
"context"
"fmt"
"io"
"log"
"net/http"

Expand Down Expand Up @@ -82,7 +81,7 @@ func (rpc *ExampleServiceRPC) Version(ctx context.Context) (*Version, error) {

func (s *ExampleServiceRPC) GetUser(ctx context.Context, header map[string]string, userID uint64) (*User, error) {
if userID == 911 {
return nil, ErrorWithCause(ErrUserNotFound, fmt.Errorf("unknown user id %d", userID))
return nil, ErrUserNotFound.WithCausef("unknown user id %d", userID)
}
if userID == 31337 {
return nil, ErrUnauthorized
Expand All @@ -91,14 +90,6 @@ func (s *ExampleServiceRPC) GetUser(ctx context.Context, header map[string]strin
panic("oh no")
}

// Legacy errors.
switch userID {
case 0:
return nil, Errorf(ErrInvalidArgument, "userId is required")
case 1000:
return nil, WrapError(ErrUnavailable, io.ErrUnexpectedEOF, "service unavailable")
}

return &User{
ID: userID,
Username: "hihi",
Expand All @@ -107,7 +98,7 @@ func (s *ExampleServiceRPC) GetUser(ctx context.Context, header map[string]strin

func (rpc *ExampleServiceRPC) FindUser(ctx context.Context, s *SearchFilter) (string, *User, error) {
if s == nil {
return "", nil, ErrorWithCause(ErrMissingArgument, fmt.Errorf("s search filter required"))
return "", nil, ErrMissingArgument.WithCausef("s search filter required")
}
name := s.Q
return s.Q, &User{
Expand Down
93 changes: 1 addition & 92 deletions _examples/golang-imports/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion _examples/golang-imports/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main

//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=./proto/api.ridl -target=../../../gen-golang -out=./api.gen.go -pkg=main -server -client -legacyErrors=true -fmt=false
//go:generate go run github.com/webrpc/webrpc/cmd/webrpc-gen -schema=./proto/api.ridl -target=../../../gen-golang -out=./api.gen.go -pkg=main -server -client -fmt=false

import (
"context"
Expand Down
5 changes: 0 additions & 5 deletions errors.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ func (e WebRPCError) Is(target error) bool {
if rpcErr, ok := target.(WebRPCError); ok {
return rpcErr.Code == e.Code
}
{{- if $opts.legacyErrors }}
if legacyErr, ok := target.(legacyError); ok {
return legacyErr.Code == e.Code
}
{{- end }}
return errors.Is(e.cause, target)
}

Expand Down
Loading
Loading