Skip to content

Commit fd317d2

Browse files
cicoyleItalyPaleAleelena-kolevskaJoshVanL
authored
Add errors package (dapr#77)
* Move dapr/concurrency to kit (dapr#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 (dapr#70) No code changes Signed-off-by: ItalyPaleAle <[email protected]> Signed-off-by: Cassandra Coyle <[email protected]> * Move dapr/utils/streams to kit (dapr#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 (dapr#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 (dapr#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]>
1 parent df64d3a commit fd317d2

File tree

6 files changed

+1333
-278
lines changed

6 files changed

+1333
-278
lines changed

errors/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Errors
2+
3+
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).
4+
5+
## Usage
6+
7+
Define the error
8+
```go
9+
import kitErrors "github.com/dapr/kit/errors"
10+
11+
// Define error in dapr pkg/api/<building_block>_errors.go
12+
func PubSubNotFound(name string, pubsubType string, metadata map[string]string) error {
13+
message := fmt.Sprintf("pubsub %s is not found", name)
14+
15+
return kitErrors.NewBuilder(
16+
grpcCodes.NotFound,
17+
http.StatusBadRequest,
18+
message,
19+
kitErrors.CodePrefixPubSub+kitErrors.CodeNotFound,
20+
).
21+
WithErrorInfo(kitErrors.CodePrefixPubSub+kitErrors.CodeNotFound, metadata).
22+
WithResourceInfo(pubsubType, name, "", message).
23+
Build()
24+
}
25+
```
26+
27+
Use the error
28+
```go
29+
import apiErrors "github.com/dapr/dapr/pkg/api/errors"
30+
31+
// Use error in dapr and pass in relevant information
32+
err = apiErrors.PubSubNotFound(pubsubName, pubsubType, metadata)
33+
34+
```

errors/codes.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright 2023 The Dapr Authors
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package errors
15+
16+
const (
17+
// Generic
18+
CodeNotFound = "NOT_FOUND"
19+
CodeNotConfigured = "NOT_CONFIGURED"
20+
CodeNotSupported = "NOT_SUPPORTED"
21+
CodeIllegalKey = "ILLEGAL_KEY"
22+
23+
// Components
24+
CodePrefixStateStore = "DAPR_STATE_"
25+
CodePrefixPubSub = "DAPR_PUBSUB_"
26+
CodePrefixBindings = "DAPR_BINDING_"
27+
CodePrefixSecretStore = "DAPR_SECRET_"
28+
CodePrefixConfigurationStore = "DAPR_CONFIGURATION_"
29+
CodePrefixLock = "DAPR_LOCK_"
30+
CodePrefixNameResolution = "DAPR_NAME_RESOLUTION_"
31+
CodePrefixMiddleware = "DAPR_MIDDLEWARE_"
32+
33+
// State
34+
CodePostfixGetStateFailed = "GET_STATE_FAILED"
35+
CodePostfixTooManyTransactions = "TOO_MANY_TRANSACTIONS"
36+
CodePostfixQueryFailed = "QUERY_FAILED"
37+
)

0 commit comments

Comments
 (0)