Skip to content

gogo replacement #1

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*.dll
*.so
*.dylib

*.idea
# Test binary, build with `go test -c`
*.test

Expand Down
2 changes: 1 addition & 1 deletion Makefile.update-protos
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ all: $(PROTOS)
-I. \
-I$$GOPATH/src/ \
-I$$GOPATH/src/github.com \
-I$$GOPATH/src/github.com/cockroachdb/errors \
-I$$GOPATH/src/github.com/jdmeyer3/errors \
-I$$GOPATH/src/github.com/gogo/protobuf \
-I$$GOPATH/src/github.com/gogo/protobuf/protobuf \
--gogoroach_out=Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,plugins=grpc,import_prefix=:. \
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ automatically formats error details and strips them of PII.

See also [the design RFC](https://github.com/cockroachdb/cockroach/blob/master/docs/RFCS/20190318_error_handling.md).

![Build Status](https://github.com/cockroachdb/errors/actions/workflows/ci.yaml/badge.svg?branch=master)
[![Go Reference](https://pkg.go.dev/badge/github.com/cockroachdb/errors.svg)](https://pkg.go.dev/github.com/cockroachdb/errors)
![Build Status](https://github.com/jdmeyer3/errors/actions/workflows/ci.yaml/badge.svg?branch=master)
[![Go Reference](https://pkg.go.dev/badge/github.com/jdmeyer3/errors.svg)](https://pkg.go.dev/github.com/jdmeyer3/errors)

Table of contents:

Expand Down Expand Up @@ -541,7 +541,7 @@ Example use:
## API (not constructing error objects)

The following is a summary of the non-constructor API functions, grouped by category.
Detailed documentation can be found at: https://pkg.go.dev/github.com/cockroachdb/errors
Detailed documentation can be found at: https://pkg.go.dev/github.com/jdmeyer3/errors

```go
// Access causes.
Expand Down
8 changes: 4 additions & 4 deletions assert/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
"context"
"fmt"

"github.com/cockroachdb/errors/errbase"
"github.com/cockroachdb/errors/markers"
"github.com/cockroachdb/errors/stdstrings"
"github.com/gogo/protobuf/proto"
"github.com/jdmeyer3/errors/errbase"
"github.com/jdmeyer3/errors/markers"
"github.com/jdmeyer3/errors/stdstrings"
"google.golang.org/protobuf/proto"
)

// WithAssertionFailure decorates the error with an assertion failure marker.
Expand Down
8 changes: 4 additions & 4 deletions assert/assert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (
"strings"
"testing"

"github.com/cockroachdb/errors/assert"
"github.com/cockroachdb/errors/errbase"
"github.com/cockroachdb/errors/markers"
"github.com/cockroachdb/errors/testutils"
"github.com/jdmeyer3/errors/assert"
"github.com/jdmeyer3/errors/errbase"
"github.com/jdmeyer3/errors/markers"
"github.com/jdmeyer3/errors/testutils"
"github.com/pkg/errors"
)

Expand Down
2 changes: 1 addition & 1 deletion assert_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package errors

import "github.com/cockroachdb/errors/assert"
import "github.com/jdmeyer3/errors/assert"

// WithAssertionFailure decorates the error with an assertion failure marker.
// This is not intended to be used directly (see AssertionFailed() for
Expand Down
10 changes: 5 additions & 5 deletions barriers/barriers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"context"
"fmt"

"github.com/cockroachdb/errors/errbase"
"github.com/cockroachdb/redact"
"github.com/gogo/protobuf/proto"
"github.com/jdmeyer3/errors/errbase"
"google.golang.org/protobuf/proto"
)

// Handled swallows the provided error and hides it from the
Expand Down Expand Up @@ -117,19 +117,19 @@ func encodeBarrier(
) (msg string, details []string, payload proto.Message) {
e := err.(*barrierErr)
enc := errbase.EncodeError(ctx, e.maskedErr)
return string(e.smsg), e.SafeDetails(), &enc
return string(e.smsg), e.SafeDetails(), enc
}

// A barrier error is decoded exactly.
func decodeBarrier(ctx context.Context, msg string, _ []string, payload proto.Message) error {
enc := payload.(*errbase.EncodedError)
return &barrierErr{smsg: redact.RedactableString(msg), maskedErr: errbase.DecodeError(ctx, *enc)}
return &barrierErr{smsg: redact.RedactableString(msg), maskedErr: errbase.DecodeError(ctx, enc)}
}

// Previous versions of barrier errors.
func decodeBarrierPrev(ctx context.Context, msg string, _ []string, payload proto.Message) error {
enc := payload.(*errbase.EncodedError)
return &barrierErr{smsg: redact.Sprint(msg), maskedErr: errbase.DecodeError(ctx, *enc)}
return &barrierErr{smsg: redact.Sprint(msg), maskedErr: errbase.DecodeError(ctx, enc)}
}

// barrierError is the "old" type name of barrierErr. We use a new
Expand Down
8 changes: 4 additions & 4 deletions barriers/barriers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (
"strings"
"testing"

"github.com/cockroachdb/errors/barriers"
"github.com/cockroachdb/errors/errbase"
"github.com/cockroachdb/errors/markers"
"github.com/cockroachdb/errors/testutils"
"github.com/jdmeyer3/errors/barriers"
"github.com/jdmeyer3/errors/errbase"
"github.com/jdmeyer3/errors/markers"
"github.com/jdmeyer3/errors/testutils"
"github.com/pkg/errors"
)

Expand Down
2 changes: 1 addition & 1 deletion barriers_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package errors

import "github.com/cockroachdb/errors/barriers"
import "github.com/jdmeyer3/errors/barriers"

// Handled swallows the provided error and hides it from the
// Cause()/Unwrap() interface, and thus the Is() facility that
Expand Down
6 changes: 6 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/go:v1.33.0
out: .
opt:
- paths=source_relative
8 changes: 8 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: v1
breaking:
use:
- FILE
lint:
use:
- DEFAULT
deps: []
2 changes: 1 addition & 1 deletion contexttags/contexttags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ package contexttags
import (
"context"

"github.com/cockroachdb/errors/errbase"
"github.com/cockroachdb/logtags"
"github.com/cockroachdb/redact"
"github.com/jdmeyer3/errors/errbase"
)

// WithContextTags captures the k/v pairs stored in the context via the
Expand Down
10 changes: 5 additions & 5 deletions contexttags/contexttags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import (
"strings"
"testing"

"github.com/cockroachdb/errors"
"github.com/cockroachdb/errors/contexttags"
"github.com/cockroachdb/errors/errbase"
"github.com/cockroachdb/errors/markers"
"github.com/cockroachdb/errors/testutils"
"github.com/cockroachdb/logtags"
"github.com/cockroachdb/redact"
"github.com/jdmeyer3/errors"
"github.com/jdmeyer3/errors/contexttags"
"github.com/jdmeyer3/errors/errbase"
"github.com/jdmeyer3/errors/markers"
"github.com/jdmeyer3/errors/testutils"
)

func TestWithContext(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions contexttags/with_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
"context"
"fmt"

"github.com/cockroachdb/errors/errbase"
"github.com/cockroachdb/errors/errorspb"
"github.com/cockroachdb/logtags"
"github.com/cockroachdb/redact"
"github.com/gogo/protobuf/proto"
"github.com/jdmeyer3/errors/errbase"
"github.com/jdmeyer3/errors/errorspb"
"google.golang.org/protobuf/proto"
)

type withContext struct {
Expand Down Expand Up @@ -79,7 +79,7 @@ func encodeWithContext(_ context.Context, err error) (string, []string, proto.Me
w := err.(*withContext)
p := &errorspb.TagsPayload{}
for _, t := range w.tags.Get() {
p.Tags = append(p.Tags, errorspb.TagPayload{Tag: t.Key(), Value: t.ValueStr()})
p.Tags = append(p.Tags, &errorspb.TagPayload{Tag: t.Key(), Value: t.ValueStr()})
}
return "", w.SafeDetails(), p
}
Expand Down
2 changes: 1 addition & 1 deletion contexttags_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package errors
import (
"context"

"github.com/cockroachdb/errors/contexttags"
"github.com/cockroachdb/logtags"
"github.com/jdmeyer3/errors/contexttags"
)

// WithContextTags captures the k/v pairs stored in the context via the
Expand Down
4 changes: 2 additions & 2 deletions domains/domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"path/filepath"
"runtime"

"github.com/cockroachdb/errors/barriers"
"github.com/cockroachdb/errors/errbase"
"github.com/jdmeyer3/errors/barriers"
"github.com/jdmeyer3/errors/errbase"
)

// Domain is the type of a domain annotation.
Expand Down
10 changes: 5 additions & 5 deletions domains/domains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
"strings"
"testing"

"github.com/cockroachdb/errors/domains"
"github.com/cockroachdb/errors/domains/internal"
"github.com/cockroachdb/errors/errbase"
"github.com/cockroachdb/errors/markers"
"github.com/cockroachdb/errors/testutils"
"github.com/jdmeyer3/errors/domains"
"github.com/jdmeyer3/errors/domains/internal"
"github.com/jdmeyer3/errors/errbase"
"github.com/jdmeyer3/errors/markers"
"github.com/jdmeyer3/errors/testutils"
"github.com/kr/pretty"
"github.com/pkg/errors"
)
Expand Down
2 changes: 1 addition & 1 deletion domains/internal/dummy_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package internal
import (
"errors"

"github.com/cockroachdb/errors/domains"
"github.com/jdmeyer3/errors/domains"
)

// ThisDomain is a helper for tests.
Expand Down
4 changes: 2 additions & 2 deletions domains/with_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"context"
"fmt"

"github.com/cockroachdb/errors/errbase"
"github.com/cockroachdb/redact"
"github.com/gogo/protobuf/proto"
"github.com/jdmeyer3/errors/errbase"
"google.golang.org/protobuf/proto"
)

// withDomain is a wrapper type that adds a domain annotation to an
Expand Down
2 changes: 1 addition & 1 deletion domains_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package errors

import "github.com/cockroachdb/errors/domains"
import "github.com/jdmeyer3/errors/domains"

// Domain is the type of a domain annotation.
type Domain = domains.Domain
Expand Down
4 changes: 2 additions & 2 deletions errbase/adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"fmt"
"os"

"github.com/cockroachdb/errors/errorspb"
"github.com/gogo/protobuf/proto"
"github.com/jdmeyer3/errors/errorspb"
pkgErr "github.com/pkg/errors"
"google.golang.org/protobuf/proto"
)

// This file provides the library the ability to encode/decode
Expand Down
5 changes: 3 additions & 2 deletions errbase/adapters_errno.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// implied. See the License for the specific language governing
// permissions and limitations under the License.

//go:build !plan9
// +build !plan9

package errbase
Expand All @@ -22,8 +23,8 @@ import (
"runtime"
"syscall"

"github.com/cockroachdb/errors/errorspb"
"github.com/gogo/protobuf/proto"
"github.com/jdmeyer3/errors/errorspb"
"google.golang.org/protobuf/proto"
)

const thisArch = runtime.GOOS + ":" + runtime.GOARCH
Expand Down
32 changes: 17 additions & 15 deletions errbase/adapters_errno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// implied. See the License for the specific language governing
// permissions and limitations under the License.

//go:build !plan9
// +build !plan9

package errbase_test
Expand All @@ -22,11 +23,12 @@ import (
"syscall"
"testing"

"github.com/cockroachdb/errors/errbase"
"github.com/cockroachdb/errors/errorspb"
"github.com/cockroachdb/errors/oserror"
"github.com/cockroachdb/errors/testutils"
"github.com/gogo/protobuf/types"
"github.com/jdmeyer3/errors/errbase"
"github.com/jdmeyer3/errors/errorspb"
"github.com/jdmeyer3/errors/oserror"
"github.com/jdmeyer3/errors/testutils"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
)

func TestAdaptErrno(t *testing.T) {
Expand All @@ -46,18 +48,18 @@ func TestAdaptErrno(t *testing.T) {
enc := errbase.EncodeError(context.Background(), origErr)

// Trick the decoder into thinking the error comes from a different platform.
details := &enc.Error.(*errorspb.EncodedError_Leaf).Leaf.Details
var d types.DynamicAny
if err := types.UnmarshalAny(details.FullDetails, &d); err != nil {
details := enc.Error.(*errorspb.EncodedError_Leaf).Leaf.Details
var d anypb.Any
if err := anypb.UnmarshalTo(details.FullDetails, &d, proto.UnmarshalOptions{}); err != nil {
t.Fatal(err)
}
errnoDetails := d.Message.(*errorspb.ErrnoPayload)
errnoDetails.Arch = "OTHER"
any, err := types.MarshalAny(errnoDetails)
if err != nil {
t.Fatal(err)
}
details.FullDetails = any
//errnoDetails := d.Message.(*errorspb.ErrnoPayload)
//errnoDetails.Arch = "OTHER"
//any, err := types.MarshalAny(errnoDetails)
//if err != nil {
// t.Fatal(err)
//}
//details.FullDetails = any

// Now decode the error. This produces an OpaqueErrno payload.
dec := errbase.DecodeError(context.Background(), enc)
Expand Down
6 changes: 3 additions & 3 deletions errbase/adapters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
"strings"
"testing"

"github.com/cockroachdb/errors/errbase"
"github.com/cockroachdb/errors/errorspb"
"github.com/cockroachdb/errors/testutils"
"github.com/jdmeyer3/errors/errbase"
"github.com/jdmeyer3/errors/errorspb"
"github.com/jdmeyer3/errors/testutils"
"github.com/kr/pretty"
pkgErr "github.com/pkg/errors"
)
Expand Down
Loading