Skip to content

Commit

Permalink
Merge remote-tracking branch 'jake/metric-error-codes' into metric-er…
Browse files Browse the repository at this point in the history
…ror-codes-impl
  • Loading branch information
jake-engelberg committed Oct 15, 2024
2 parents 6bd574f + 44c31be commit 77fc2d7
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 120 deletions.
27 changes: 14 additions & 13 deletions pkg/api/errors/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"google.golang.org/grpc/codes"

"github.com/dapr/components-contrib/metadata"
"github.com/dapr/dapr/pkg/messages/errorcodes"
"github.com/dapr/kit/errors"
)

Expand Down Expand Up @@ -79,7 +80,7 @@ func (p PubSubError) PublishMessage(topic string, err error) error {
codes.Internal,
http.StatusInternalServerError,
fmt.Sprintf("error when publishing to topic %s in pubsub %s: %s", topic, p.name, err),
"ERR_PUBSUB_PUBLISH_MESSAGE",
errorcodes.PubsubPublishMessage,
"PUBLISH_MESSAGE",
)
}
Expand All @@ -89,7 +90,7 @@ func (p *PubSubError) PublishForbidden(topic, appID string, err error) error {
codes.PermissionDenied,
http.StatusForbidden,
fmt.Sprintf("topic %s is not allowed for app id %s", topic, appID),
"ERR_PUBSUB_FORBIDDEN",
errorcodes.PubsubForbidden,
"FORBIDDEN",
)
}
Expand All @@ -102,7 +103,7 @@ func (p PubSubError) TestNotFound(topic string, err error) error {
codes.NotFound,
http.StatusBadRequest,
fmt.Sprintf("pubsub '%s' not found", p.name),
"ERR_PUBSUB_NOT_FOUND",
errorcodes.PubsubNotFound,
"TEST_NOT_FOUND",
)
}
Expand All @@ -113,7 +114,7 @@ func (p *PubSubMetadataError) NotFound() error {
codes.InvalidArgument,
http.StatusNotFound,
fmt.Sprintf("%s %s is not found", metadata.PubSubType, p.p.name),
"ERR_PUBSUB_NOT_FOUND",
errorcodes.PubsubNotFound,
errors.CodeNotFound,
)
}
Expand All @@ -124,7 +125,7 @@ func (p *PubSubMetadataError) NotConfigured() error {
codes.FailedPrecondition,
http.StatusBadRequest,
fmt.Sprintf("%s %s is not configured", metadata.PubSubType, p.p.name),
"ERR_PUBSUB_NOT_CONFIGURED",
errorcodes.PubsubNotConfigured,
errors.CodeNotConfigured,
)
}
Expand All @@ -141,7 +142,7 @@ func (p *PubSubMetadataError) NameEmpty() error {
codes.InvalidArgument,
http.StatusNotFound,
"pubsub name is empty",
"ERR_PUBSUB_EMPTY",
errorcodes.PubsubEmpty,
"NAME_EMPTY",
)
}
Expand All @@ -151,7 +152,7 @@ func (p *PubSubMetadataError) TopicEmpty() error {
codes.InvalidArgument,
http.StatusNotFound,
"topic is empty in pubsub "+p.p.name,
"ERR_TOPIC_NAME_EMPTY",
errorcodes.TopicNameEmpty,
"TOPIC_NAME_EMPTY",
)
}
Expand All @@ -161,7 +162,7 @@ func (p *PubSubMetadataError) DeserializeError(err error) error {
codes.InvalidArgument,
http.StatusBadRequest,
fmt.Sprintf("failed deserializing metadata. Error: %s", err),
"ERR_PUBSUB_REQUEST_METADATA",
errorcodes.PubsubRequestMetadata,
"METADATA_DESERIALIZATION",
)
}
Expand All @@ -171,7 +172,7 @@ func (p *PubSubMetadataError) CloudEventCreation() error {
codes.InvalidArgument,
http.StatusInternalServerError,
"cannot create cloudevent",
"ERR_PUBSUB_CLOUD_EVENTS_SER",
errorcodes.PubsubCloudEventsSer,
"CLOUD_EVENT_CREATION",
)
}
Expand All @@ -185,7 +186,7 @@ func (p *PubSubTopicError) MarshalEnvelope() error {
codes.InvalidArgument,
http.StatusBadRequest,
msg,
"ERR_PUBSUB_EVENTS_SER",
errorcodes.PubsubEventsSer,
"MARSHAL_ENVELOPE",
)
}
Expand All @@ -200,7 +201,7 @@ func (p *PubSubTopicError) MarshalEvents() error {
codes.InvalidArgument,
http.StatusBadRequest,
message,
"ERR_PUBSUB_EVENTS_SER",
errorcodes.PubsubEventsSer,
"MARSHAL_EVENTS",
)
}
Expand All @@ -216,7 +217,7 @@ func (p *PubSubTopicError) UnmarshalEvents(err error) error {
codes.InvalidArgument,
http.StatusBadRequest,
message,
"ERR_PUBSUB_EVENTS_SER",
errorcodes.PubsubEventsSer,
"UNMARSHAL_EVENTS",
)
}
Expand All @@ -238,7 +239,7 @@ func PubSubOutbox(appID string, err error) error {
codes.Internal,
http.StatusInternalServerError,
message,
"ERR_PUBLISH_OUTBOX",
errorcodes.PublishOutbox,
).WithErrorInfo(errors.CodePrefixPubSub+"OUTBOX", map[string]string{
"appID": appID, "error": err.Error(),
}).Build()
Expand Down
15 changes: 8 additions & 7 deletions pkg/api/errors/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"google.golang.org/grpc/codes"

"github.com/dapr/components-contrib/metadata"
"github.com/dapr/dapr/pkg/messages/errorcodes"
"github.com/dapr/kit/errors"
)

Expand All @@ -47,7 +48,7 @@ func (s *StateStoreError) NotFound(appID string) error {
codes.InvalidArgument,
http.StatusBadRequest,
msg,
"ERR_STATE_STORE_NOT_FOUND",
errorcodes.StateStoreNotFound,
),
errors.CodeNotFound,
meta,
Expand All @@ -66,7 +67,7 @@ func (s *StateStoreError) NotConfigured(appID string) error {
codes.FailedPrecondition,
http.StatusInternalServerError,
msg,
"ERR_STATE_STORE_NOT_CONFIGURED",
errorcodes.StateStoreNotConfigured,
),
errors.CodeNotConfigured,
meta,
Expand All @@ -79,7 +80,7 @@ func (s *StateStoreError) InvalidKeyName(key string, msg string) error {
codes.InvalidArgument,
http.StatusBadRequest,
msg,
"ERR_MALFORMED_REQUEST",
errorcodes.MalformedRequest,
).WithFieldViolation(key, msg),
errors.CodeIllegalKey,
nil,
Expand All @@ -94,7 +95,7 @@ func (s *StateStoreError) TransactionsNotSupported() error {
codes.Unimplemented,
http.StatusInternalServerError,
fmt.Sprintf("state store %s doesn't support transactions", s.name),
"ERR_STATE_STORE_NOT_SUPPORTED", // TODO: @elena-kolevska this code misleading and also used for different things ("query unsupported"); it should be removed in the next major version
errorcodes.StateStoreNotSupported, // TODO: @elena-kolevska this code misleading and also used for different things ("query unsupported"); it should be removed in the next major version
).WithHelpLink("https://docs.dapr.io/reference/components-reference/supported-state-stores/", "Check the list of state stores and the features they support"),
"TRANSACTIONS_NOT_SUPPORTED",
nil,
Expand All @@ -107,7 +108,7 @@ func (s *StateStoreError) TooManyTransactionalOps(count int, max int) error {
codes.InvalidArgument,
http.StatusBadRequest,
fmt.Sprintf("the transaction contains %d operations, which is more than what the state store supports: %d", count, max),
"ERR_STATE_STORE_TOO_MANY_TRANSACTIONS",
errorcodes.StateStoreTooManyTransactions,
),
"TOO_MANY_TRANSACTIONS",
map[string]string{
Expand All @@ -125,7 +126,7 @@ func (s *StateStoreError) QueryUnsupported() error {
codes.Internal,
http.StatusInternalServerError,
"state store does not support querying",
"ERR_STATE_STORE_NOT_SUPPORTED",
errorcodes.StateStoreNotSupported,
),
"QUERYING_"+errors.CodeNotSupported,
nil,
Expand All @@ -138,7 +139,7 @@ func (s *StateStoreError) QueryFailed(detail string) error {
codes.Internal,
http.StatusInternalServerError,
fmt.Sprintf("state store %s query failed: %s", s.name, detail),
"ERR_STATE_QUERY",
errorcodes.StateQuery,
),
errors.CodePostfixQueryFailed,
nil,
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/http/directmessaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/dapr/dapr/pkg/api/http/endpoints"
diagConsts "github.com/dapr/dapr/pkg/diagnostics/consts"
"github.com/dapr/dapr/pkg/messages"
"github.com/dapr/dapr/pkg/messages/errorcodes"
invokev1 "github.com/dapr/dapr/pkg/messaging/v1"
"github.com/dapr/dapr/pkg/resiliency"
)
Expand Down Expand Up @@ -186,7 +187,7 @@ func (a *api) onDirectMessage(w http.ResponseWriter, r *http.Request) {
if rErr != nil {
return rResp, invokeError{
statusCode: http.StatusInternalServerError,
msg: NewErrorResponse("ERR_MALFORMED_RESPONSE", rErr.Error()).JSONErrorValue(),
msg: NewErrorResponse(errorcodes.MalformedResponse, rErr.Error()).JSONErrorValue(),
}
}
} else {
Expand Down
Loading

0 comments on commit 77fc2d7

Please sign in to comment.