Skip to content

Commit

Permalink
Merge pull request #1022 from qazwsxedckll/extend-error-response
Browse files Browse the repository at this point in the history
Extend error response
  • Loading branch information
rogeralsing authored Jan 24, 2024
2 parents 7ae4563 + 86a3357 commit f36d1cf
Show file tree
Hide file tree
Showing 318 changed files with 8,819 additions and 904 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,6 @@ FakesAssemblies/
/go.work
/go.work.sum

# go.sum of examples
_examples/**/go.sum
_examples/**/go.work.sum
.vscode/

/test_report.html
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build:

# {{{ test

PACKAGES := $(shell go list ./... | grep -v "/_examples/" | grep -v "/persistence" | grep -v "/scheduler")
PACKAGES := $(shell go list ./... | grep -v "/examples/" | grep -v "/persistence" | grep -v "/scheduler")



Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ This command exectutes all tests in the repository except for consul integration
those tests). We also skip directories that don't contain any tests.

```
go test `go list ./... | grep -v "/_examples/" | grep -v "/persistence" | grep -v "/scheduler"`
go test `go list ./... | grep -v "/examples/" | grep -v "/persistence" | grep -v "/scheduler"`
```
## Hello world

Expand Down
3 changes: 0 additions & 3 deletions _examples/cluster-basic/shared/build.sh

This file was deleted.

7 changes: 0 additions & 7 deletions _examples/cluster-basic/shared/protos.proto

This file was deleted.

2 changes: 0 additions & 2 deletions _examples/cluster-broadcast/shared/build.sh

This file was deleted.

3 changes: 0 additions & 3 deletions _examples/cluster-eventstream-broadcast/build.sh

This file was deleted.

7 changes: 0 additions & 7 deletions _examples/cluster-eventstream-broadcast/protos.proto

This file was deleted.

7 changes: 0 additions & 7 deletions _examples/cluster-eventstream-broadcast/protos_grain.pb.go

This file was deleted.

2 changes: 0 additions & 2 deletions _examples/cluster-metrics/shared/build.sh

This file was deleted.

1 change: 0 additions & 1 deletion _examples/cluster-pubsub-batching-producer/build.sh

This file was deleted.

43 changes: 0 additions & 43 deletions _examples/cluster-pubsub-batching-producer/go.mod

This file was deleted.

7 changes: 0 additions & 7 deletions _examples/cluster-pubsub-batching-producer/protos.proto

This file was deleted.

2 changes: 0 additions & 2 deletions _examples/cluster-pubsub/build.sh

This file was deleted.

43 changes: 0 additions & 43 deletions _examples/cluster-pubsub/go.mod

This file was deleted.

2 changes: 0 additions & 2 deletions _examples/cluster-restartgracefully/shared/build.sh

This file was deleted.

68 changes: 0 additions & 68 deletions _examples/opentelemetry-custom-provider/main.go

This file was deleted.

7 changes: 0 additions & 7 deletions _examples/remote-channels/messages/protos.proto

This file was deleted.

5 changes: 0 additions & 5 deletions _examples/remote-ssl/go.mod

This file was deleted.

4 changes: 2 additions & 2 deletions cluster/cluster.pb.go

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

4 changes: 2 additions & 2 deletions cluster/cluster_test_tool/pubsub_cluster.pb.go

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

82 changes: 82 additions & 0 deletions cluster/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package cluster

import (
"errors"
"fmt"
)

const (
ErrorReason_OK = "OK"
ErrorReason_CANCELLED = "CANCELLED"
ErrorReason_UNKNOWN = "UNKNOWN"
ErrorReason_INVALID_ARGUMENT = "INVALID_ARGUMENT"
ErrorReason_DEADLINE_EXCEEDED = "DEADLINE_EXCEEDED"
ErrorReason_NOT_FOUND = "NOT_FOUND"
ErrorReason_ALREADY_EXISTS = "ALREADY_EXISTS"
ErrorReason_PERMISSION_DENIED = "PERMISSION_DENIED"
ErrorReason_RESOURCE_EXHAUSTED = "RESOURCE_EXHAUSTED"
ErrorReason_FAILED_PRECONDITION = "FAILED_PRECONDITION"
ErrorReason_ABORTED = "ABORTED"
ErrorReason_OUT_OF_RANGE = "OUT_OF_RANGE"
ErrorReason_UNIMPLEMENTED = "UNIMPLEMENTED"
ErrorReason_INTERNAL = "INTERNAL"
ErrorReason_UNAVAILABLE = "UNAVAILABLE"
ErrorReason_DATA_LOSS = "DATA_LOSS"
ErrorReason_UNAUTHENTICATED = "UNAUTHENTICATED"
)

func NewGrainErrorResponse(reason, message string) *GrainErrorResponse {
return &GrainErrorResponse{
Reason: reason,
Message: message,
}
}

func NewGrainErrorResponsef(reason, format string, args ...interface{}) *GrainErrorResponse {
return &GrainErrorResponse{
Reason: reason,
Message: fmt.Sprintf(format, args...),
}
}

func (m *GrainErrorResponse) Error() string {
return fmt.Sprintf("grain error response, reason: %s, message: %s, metadata: %v", m.Reason, m.Message, m.Metadata)
}

func (m *GrainErrorResponse) Is(err error) bool {
if e := new(GrainErrorResponse); errors.As(err, &e) {
return e.Reason == m.Reason
}
return false
}

func (m *GrainErrorResponse) Errorf(format string, args ...interface{}) error {
return NewGrainErrorResponse(m.Reason, fmt.Sprintf(format, args...))
}

func (m *GrainErrorResponse) WithMetadata(metadata map[string]string) *GrainErrorResponse {
m.Metadata = metadata
return m
}

func Reason(err error) string {
if err == nil {
return ErrorReason_UNKNOWN
}
return FromError(err).Reason
}

func FromError(err error) *GrainErrorResponse {
if err == nil {
return nil
}
if e := new(GrainErrorResponse); errors.As(err, &e) {
return e
}

ret := NewGrainErrorResponse(
ErrorReason_UNKNOWN,
err.Error(),
)
return ret
}
4 changes: 2 additions & 2 deletions cluster/gossip.pb.go

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

Loading

0 comments on commit f36d1cf

Please sign in to comment.