Skip to content

Commit

Permalink
Add errors package (#77)
Browse files Browse the repository at this point in the history
* Move dapr/concurrency to kit (#72)

* Move dapr/concurrency to kit

Does not include any code change

Signed-off-by: ItalyPaleAle <[email protected]>

* Fixed copyright year

Signed-off-by: ItalyPaleAle <[email protected]>

* Improved memory usage in error collection

Signed-off-by: ItalyPaleAle <[email protected]>

---------

Signed-off-by: ItalyPaleAle <[email protected]>
Signed-off-by: Cassandra Coyle <[email protected]>

* Move `pkg/signals` from dapr/dapr to kit (#70)

No code changes

Signed-off-by: ItalyPaleAle <[email protected]>
Signed-off-by: Cassandra Coyle <[email protected]>

* Move dapr/utils/streams to kit (#68)

* Move dapr/utils/streams to kit

No code changes

Signed-off-by: ItalyPaleAle <[email protected]>

* 💄

Signed-off-by: ItalyPaleAle <[email protected]>

* Lint

Signed-off-by: ItalyPaleAle <[email protected]>

---------

Signed-off-by: ItalyPaleAle <[email protected]>
Signed-off-by: Cassandra Coyle <[email protected]>

* Migrate metadata decoder from components-contrib to kit (#74)

* Migrate metadata decoder from components-contrib to kit

Required creating the `utils` package for utils.IsTruthy too (ported from runtime)

Signed-off-by: ItalyPaleAle <[email protected]>

* Lint

Signed-off-by: ItalyPaleAle <[email protected]>

---------

Signed-off-by: ItalyPaleAle <[email protected]>
Signed-off-by: Cassandra Coyle <[email protected]>

* initial standardized err pkg: errfmt

Signed-off-by: Cassandra Coyle <[email protected]>

* tweaks to error pkg and update tests. need to confirm reason

Signed-off-by: Cassandra Coyle <[email protected]>

* cleanup test

Signed-off-by: Cassandra Coyle <[email protected]>

* add new func for err. change to protojson for http. need to figure out grpc status tho

Signed-off-by: Cassandra Coyle <[email protected]>

* update status name

Signed-off-by: Cassandra Coyle <[email protected]>

* wip: update JSONErrorValue

Signed-off-by: Cassandra Coyle <[email protected]>

* Updates err to json conversion. Organises error messages and codes

Signed-off-by: Elena Kolevska <[email protected]>
Signed-off-by: Cassandra Coyle <[email protected]>

* add type to http json output. tests are a WIP

Signed-off-by: Cassandra Coyle <[email protected]>

* add all details, update tests, prefixes/postfixes

Signed-off-by: Cassandra Coyle <[email protected]>

* add README

Signed-off-by: Cassandra Coyle <[email protected]>

* use strongly-typed struct for errJSON

Signed-off-by: Cassandra Coyle <[email protected]>

* update README

Signed-off-by: Cassandra Coyle <[email protected]>

* Adds the option to add a help link detail and a field violation detail

Signed-off-by: Elena Kolevska <[email protected]>
Signed-off-by: Cassandra Coyle <[email protected]>

* Update fswatcher to use /events/batcher (#75)

* Update fswatcher to use /events/batcher

Signed-off-by: joshvanl <[email protected]>

* Linting

Signed-off-by: joshvanl <[email protected]>

* Linting

Signed-off-by: joshvanl <[email protected]>

* Add sleep to wait for windows fsnotify to become ready

Signed-off-by: joshvanl <[email protected]>

* Increase time for event to be received to 1 second

Signed-off-by: joshvanl <[email protected]>

---------

Signed-off-by: joshvanl <[email protected]>
Signed-off-by: Cassandra Coyle <[email protected]>

* Adds tests for WithHelp and err.WithFieldViolation

Signed-off-by: Elena Kolevska <[email protected]>
Signed-off-by: Cassandra Coyle <[email protected]>

* rebase and update proto field access to rebased code

Signed-off-by: Cassandra Coyle <[email protected]>

* gofumpt

Signed-off-by: Cassandra Coyle <[email protected]>

* errJson -> errJSON and update proto field access

Signed-off-by: Cassandra Coyle <[email protected]>

* HttpCode -> HTTPCode per CI warnings

Signed-off-by: Cassandra Coyle <[email protected]>

* rm reason since its not used

Signed-off-by: Cassandra Coyle <[email protected]>

* update return type in README example

Signed-off-by: Cassandra Coyle <[email protected]>

* use builder, add errorInfo check to Build(), update and add tests for new funcs, add getters for grpc/http codes

Signed-off-by: Cassandra Coyle <[email protected]>

* appease CI

Signed-off-by: Cassandra Coyle <[email protected]>

* update README

Signed-off-by: Cassandra Coyle <[email protected]>

* make GRPCStatus val receiver

Signed-off-by: Cassandra Coyle <[email protected]>

* Update messages.go

Signed-off-by: Artur Souza <[email protected]>

* add test to ensure we have a switch for all google err_detail types

Signed-off-by: Cassandra Coyle <[email protected]>

* rebase and update log

Signed-off-by: Cassandra Coyle <[email protected]>

* re-export ErrorBuilder

Signed-off-by: Cassandra Coyle <[email protected]>

* Update errors/errors.go

Co-authored-by: Alessandro (Ale) Segala <[email protected]>
Signed-off-by: Cassie Coyle <[email protected]>

* use ast pkg to dynamically grab our errTypes in the switch case instead of hard coding it

Signed-off-by: Cassandra Coyle <[email protected]>

* appease CI

Signed-off-by: Cassandra Coyle <[email protected]>

* add FromError func

Signed-off-by: Cassandra Coyle <[email protected]>

* account for error wrapping

Signed-off-by: Cassandra Coyle <[email protected]>

---------

Signed-off-by: Alessandro (Ale) Segala <[email protected]>
Signed-off-by: Cassandra Coyle <[email protected]>
Signed-off-by: Elena Kolevska <[email protected]>
Signed-off-by: joshvanl <[email protected]>
Signed-off-by: Cassie Coyle <[email protected]>
Co-authored-by: Alessandro (Ale) Segala <[email protected]>
Co-authored-by: Elena Kolevska <[email protected]>
Co-authored-by: Josh van Leeuwen <[email protected]>
  • Loading branch information
4 people authored Dec 19, 2023
1 parent df64d3a commit fd317d2
Show file tree
Hide file tree
Showing 6 changed files with 1,333 additions and 278 deletions.
34 changes: 34 additions & 0 deletions errors/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Errors

The standardizing of errors to be used in Dapr based on the gRPC Richer Error Model and [accepted dapr/proposal](https://github.com/dapr/proposals/blob/main/0009-BCIRS-error-handling-codes.md).

## Usage

Define the error
```go
import kitErrors "github.com/dapr/kit/errors"

// Define error in dapr pkg/api/<building_block>_errors.go
func PubSubNotFound(name string, pubsubType string, metadata map[string]string) error {
message := fmt.Sprintf("pubsub %s is not found", name)

return kitErrors.NewBuilder(
grpcCodes.NotFound,
http.StatusBadRequest,
message,
kitErrors.CodePrefixPubSub+kitErrors.CodeNotFound,
).
WithErrorInfo(kitErrors.CodePrefixPubSub+kitErrors.CodeNotFound, metadata).
WithResourceInfo(pubsubType, name, "", message).
Build()
}
```

Use the error
```go
import apiErrors "github.com/dapr/dapr/pkg/api/errors"

// Use error in dapr and pass in relevant information
err = apiErrors.PubSubNotFound(pubsubName, pubsubType, metadata)

```
37 changes: 37 additions & 0 deletions errors/codes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright 2023 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package errors

const (
// Generic
CodeNotFound = "NOT_FOUND"
CodeNotConfigured = "NOT_CONFIGURED"
CodeNotSupported = "NOT_SUPPORTED"
CodeIllegalKey = "ILLEGAL_KEY"

// Components
CodePrefixStateStore = "DAPR_STATE_"
CodePrefixPubSub = "DAPR_PUBSUB_"
CodePrefixBindings = "DAPR_BINDING_"
CodePrefixSecretStore = "DAPR_SECRET_"
CodePrefixConfigurationStore = "DAPR_CONFIGURATION_"
CodePrefixLock = "DAPR_LOCK_"
CodePrefixNameResolution = "DAPR_NAME_RESOLUTION_"
CodePrefixMiddleware = "DAPR_MIDDLEWARE_"

// State
CodePostfixGetStateFailed = "GET_STATE_FAILED"
CodePostfixTooManyTransactions = "TOO_MANY_TRANSACTIONS"
CodePostfixQueryFailed = "QUERY_FAILED"
)
Loading

0 comments on commit fd317d2

Please sign in to comment.