Skip to content
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

PubSub API: standardize err msgs #7322

Merged
merged 60 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
e35dd15
wip
cicoyle Nov 18, 2023
53c93b5
add err consts
cicoyle Nov 18, 2023
7d6cb90
wip
cicoyle Nov 20, 2023
5862a26
wip, need to get latest
cicoyle Dec 12, 2023
8ed2001
rm unintentional changes
cicoyle Dec 12, 2023
d4ccc6b
fix dependencies
cicoyle Dec 13, 2023
ca83b78
rm most of the predefined pubsub errors and convert to kitError
cicoyle Dec 18, 2023
80121c1
rm output err and make it standardized
cicoyle Dec 18, 2023
7183771
cleanup
cicoyle Dec 19, 2023
4cfad62
use kit pr that just got merged
cicoyle Dec 19, 2023
2236382
use FromError() from kit
cicoyle Dec 19, 2023
8eadcae
cleanup
cicoyle Dec 19, 2023
430fdbb
rm fasthttpResponseWithKitError
cicoyle Dec 19, 2023
7c1682b
add readme and pubsub error codes
cicoyle Dec 19, 2023
4bde15f
add grpc integration tests for ones that don't require pluggable pubsub
cicoyle Dec 20, 2023
4f76dfc
--amend
cicoyle Dec 20, 2023
f5e6bb0
wip, need to add pluggable pubsub to grpc, added it for http integrat…
cicoyle Dec 22, 2023
936178c
cleanup
cicoyle Jan 2, 2024
96cc3b0
fix unintentional rebase change
cicoyle Jan 3, 2024
2d46105
gofumpt
cicoyle Jan 3, 2024
f460afd
make lint
cicoyle Jan 3, 2024
a7db542
kitErrors & apiErrors -> kiterrors & apierrors
cicoyle Jan 3, 2024
836761a
change fasthttpRespond -> universalFastHTTPErrorResponder && add pubs…
cicoyle Jan 3, 2024
7d613d2
add missing err
cicoyle Jan 3, 2024
1fdab7b
update apierrors.PubSubMetadataDeserialize
cicoyle Jan 3, 2024
48293e5
rm redundant err
cicoyle Jan 3, 2024
3fa356f
add log line for err
cicoyle Jan 3, 2024
e41b5e4
make lint
cicoyle Jan 3, 2024
ce9fbcf
rm go.mod changes to mv to a new PR
cicoyle Jan 4, 2024
9a10415
Merge branch 'master' into feat-standardize-err-msgs
mukundansundar Jan 4, 2024
c25ec8c
rm README since elena has it in her PR
cicoyle Jan 4, 2024
5db1fbb
Merge branch 'master' into feat-standardize-err-msgs
cicoyle Jan 5, 2024
18a2d6c
fix make lint
cicoyle Jan 5, 2024
453fc00
Merge branch 'master' into feat-standardize-err-msgs
dapr-bot Jan 8, 2024
ae9f6a0
pull out consts
cicoyle Jan 8, 2024
8c1ab72
Merge branch 'master' into feat-standardize-err-msgs
dapr-bot Jan 9, 2024
2257475
Merge branch 'master' into feat-standardize-err-msgs
dapr-bot Jan 9, 2024
6c566f3
merge in master and resolve make lint issues
cicoyle Jan 9, 2024
665c026
Merge branch 'master' into feat-standardize-err-msgs
dapr-bot Jan 10, 2024
d30b965
Merge branch 'master' into feat-standardize-err-msgs
dapr-bot Jan 10, 2024
97d097d
Merge branch 'master' into feat-standardize-err-msgs
dapr-bot Jan 10, 2024
c94536e
Merge branch 'master' into feat-standardize-err-msgs
dapr-bot Jan 11, 2024
9b00370
Merge branch 'master' into feat-standardize-err-msgs
dapr-bot Jan 11, 2024
843353a
Merge branch 'master' into feat-standardize-err-msgs
dapr-bot Jan 11, 2024
1e83ae6
Merge branch 'master' into feat-standardize-err-msgs
dapr-bot Jan 11, 2024
411ea92
Merge branch 'master' into feat-standardize-err-msgs
dapr-bot Jan 12, 2024
a481543
merge in master
cicoyle Jan 15, 2024
bc17a32
resolve merge conflict issues
cicoyle Jan 15, 2024
22d2265
make generic NotFound && NotConfigured funcs for error codes
cicoyle Jan 15, 2024
233a1fe
make lint
cicoyle Jan 15, 2024
8d54f65
Merge branch 'master' into feat-standardize-err-msgs
dapr-bot Jan 15, 2024
a591092
errors.As -> errors.Is and use switch instead of if based on PR feedback
cicoyle Jan 15, 2024
a5e8529
revert back to errors.Is() to make tests pass again
cicoyle Jan 15, 2024
c452781
add back ' store' to state store output for errors
cicoyle Jan 15, 2024
24d1457
update test since switched to generic NotFound error and fix typo
cicoyle Jan 15, 2024
604c00d
make tests pass for state and hotreload. address error msg
cicoyle Jan 15, 2024
5f3f28f
make line more concise
cicoyle Jan 15, 2024
d68b1d8
fix some test failures. need to look into secret failure that are occ…
cicoyle Jan 15, 2024
ccf3580
Merge branch 'master' into feat-standardize-err-msgs
dapr-bot Jan 16, 2024
bf6cd0a
Merge branch 'master' into feat-standardize-err-msgs
dapr-bot Jan 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions pkg/api/errors/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package errors

import (
"fmt"

"google.golang.org/grpc/codes"

kiterrors "github.com/dapr/kit/errors"
)

func NotFound(name string, componentType string, metadata map[string]string, grpcCode codes.Code, httpCode int, legacyTag string, reason string) error {
message := fmt.Sprintf("%s %s is not found", componentType, name)

return kiterrors.NewBuilder(
grpcCode,
httpCode,
message,
legacyTag,
).
WithErrorInfo(reason, metadata).
Build()
}

func NotConfigured(name string, componentType string, metadata map[string]string, grpcCode codes.Code, httpCode int, legacyTag string, reason string) error {
message := fmt.Sprintf("%s %s is not configured", componentType, name)

return kiterrors.NewBuilder(
grpcCode,
httpCode,
message,
legacyTag,
).
WithErrorInfo(reason, metadata).
Build()
}
186 changes: 186 additions & 0 deletions pkg/api/errors/pubsub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/*
Copyright 2022 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

import (
"fmt"
"net/http"

grpcCodes "google.golang.org/grpc/codes"

kiterrors "github.com/dapr/kit/errors"
)

const (
InFixTopic = "TOPIC"
PostFixNameEmpty = "NAME_EMPTY"
PostFixMetadataDeserialization = "METADATA_DESERIALIZATION"
PostFixPublishMessage = "PUBLISH_MESSAGE"
PostFixCloudEventCreation = "CLOUD_EVENT_CREATION"
PostFixMarshalEnvelope = "MARSHAL_ENVELOPE"
PostFixMarshalEvents = "MARSHAL_EVENTS"
PostFixUnMarshalEvents = "UNMARSHAL_EVENTS"
PostFixForbidden = "FORBIDDEN"
PostFixOutbox = "OUTBOX"
)

func PubSubNameEmpty(name string, pubsubType string, metadata map[string]string) error {
message := "pubsub name is empty"
return kiterrors.NewBuilder(
grpcCodes.InvalidArgument,
http.StatusNotFound,
message,
"ERR_PUBSUB_EMPTY",
).
WithErrorInfo(kiterrors.CodePrefixPubSub+PostFixNameEmpty, metadata).
WithResourceInfo(pubsubType, name, "", message).
Build()
}

func PubSubTopicEmpty(name string, pubsubType string, metadata map[string]string) error {
message := fmt.Sprintf("topic is empty in pubsub %s", name)
return kiterrors.NewBuilder(
grpcCodes.InvalidArgument,
http.StatusNotFound,
message,
"ERR_TOPIC_EMPTY",
).
WithErrorInfo(kiterrors.CodePrefixPubSub+InFixTopic+PostFixNameEmpty, metadata).
WithResourceInfo(pubsubType, name, "", message).
Build()
}

func PubSubMetadataDeserialize(name string, pubsubType string, metadata map[string]string, err error) error {
message := fmt.Sprintf("failed deserializing metadata. Error: %s", err.Error())
return kiterrors.NewBuilder(
grpcCodes.InvalidArgument,
http.StatusBadRequest,
message,
"ERR_PUBSUB_REQUEST_METADATA",
).
WithErrorInfo(kiterrors.CodePrefixPubSub+PostFixMetadataDeserialization, metadata).
WithResourceInfo(pubsubType, name, "", message).
Build()
}

func PubSubPublishMessage(name string, pubsubType string, topic string, err error) error {
message := fmt.Sprintf("error when publishing to topic %s in pubsub %s: %s", topic, name, err.Error())
return kiterrors.NewBuilder(
grpcCodes.Internal,
http.StatusInternalServerError,
message,
"ERR_PUBSUB_PUBLISH_MESSAGE",
).
WithErrorInfo(kiterrors.CodePrefixPubSub+PostFixPublishMessage, map[string]string{"topic": topic, "error": err.Error()}).
WithResourceInfo(pubsubType, name, "", message).
Build()
}

func PubSubCloudEventCreation(name string, pubsubType string, metadata map[string]string) error {
message := "cannot create cloudevent"

return kiterrors.NewBuilder(
grpcCodes.InvalidArgument,
http.StatusInternalServerError,
message,
"ERR_PUBSUB_CLOUD_EVENTS_SER",
).
WithErrorInfo(kiterrors.CodePrefixPubSub+PostFixCloudEventCreation, metadata).
WithResourceInfo(pubsubType, name, "", message).
Build()
}

func PubSubMarshalEnvelope(name string, topic string, pubsubType string, metadata map[string]string) error {
message := fmt.Sprintf("error when marshalling cloud event envelope for topic %s pubsub %s", topic, name)

return kiterrors.NewBuilder(
grpcCodes.InvalidArgument,
http.StatusInternalServerError,
message,
"ERR_PUBSUB_CLOUD_EVENTS_SER",
).
WithErrorInfo(kiterrors.CodePrefixPubSub+PostFixMarshalEnvelope, metadata).
WithResourceInfo(pubsubType, name, "", message).
Build()
}

func PubSubMarshalEvents(name string, pubsubType string, topic string, metadata map[string]string) error {
message := fmt.Sprintf("error marshaling events to bytes for topic %s pubsub %s", topic, name)

return kiterrors.NewBuilder(
grpcCodes.InvalidArgument,
http.StatusBadRequest,
message+". error: "+metadata["error"],
"ERR_PUBSUB_EVENTS_SER",
).
WithErrorInfo(kiterrors.CodePrefixPubSub+PostFixMarshalEvents, metadata).
WithResourceInfo(pubsubType, name, "", message).
Build()
}

// PubSubUnMarshalEvents only occurs in http/api.go
func PubSubUnMarshalEvents(name string, pubsubType string, topic string, metadata map[string]string, err error) error {
message := fmt.Sprintf("error when unmarshaling the request for topic %s pubsub %s: %s", topic, name, err.Error())

return kiterrors.NewBuilder(
grpcCodes.InvalidArgument,
http.StatusBadRequest,
message,
"ERR_PUBSUB_EVENTS_SER",
).
WithErrorInfo(kiterrors.CodePrefixPubSub+PostFixUnMarshalEvents, metadata).
WithResourceInfo(pubsubType, name, "", message).
Build()
}

func PubSubPublishForbidden(name string, pubsubType string, topic string, appID string, err error) error {
message := fmt.Sprintf("topic %s is not allowed for app id %s", topic, appID)
return kiterrors.NewBuilder(
grpcCodes.PermissionDenied,
http.StatusForbidden,
message,
"ERR_PUBSUB_FORBIDDEN",
).
WithErrorInfo(kiterrors.CodePrefixPubSub+PostFixForbidden, map[string]string{"topic": topic, "error": err.Error()}).
WithResourceInfo(pubsubType, name, "", message).
Build()
}

// This is specifically for the error we are expecting for the api_tests. The not found
// expected error codes are different than the existing ones for PubSubNotFound, hence
// why this one is needed
func PubSubTestNotFound(name string, pubsubType string, topic string, err error) error {
message := fmt.Sprintf("pubsub '%s' not found", name)
return kiterrors.NewBuilder(
grpcCodes.NotFound,
http.StatusBadRequest,
message,
"ERR_PUBSUB_NOT_FOUND",
).
WithErrorInfo(kiterrors.CodePrefixPubSub+"TEST"+kiterrors.CodeNotFound, map[string]string{"topic": topic, "error": err.Error()}).
WithResourceInfo(pubsubType, name, "", message).
Build()
}

func PubSubOubox(appID string, err error) error {
message := fmt.Sprintf("error while publishing outbox message: %s", err.Error())
return kiterrors.NewBuilder(
grpcCodes.Internal,
http.StatusInternalServerError,
message,
"ERR_PUBLISH_OUTBOX",
).
WithErrorInfo(kiterrors.CodePrefixPubSub+PostFixOutbox, map[string]string{"appID": appID, "error": err.Error()}).
Build()
}
22 changes: 0 additions & 22 deletions pkg/api/errors/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,6 @@ import (
kiterrors "github.com/dapr/kit/errors"
)

func StateStoreNotConfigured() error {
return kiterrors.NewBuilder(
codes.FailedPrecondition,
http.StatusInternalServerError,
"state store is not configured",
"ERR_STATE_STORE_NOT_CONFIGURED",
).
WithErrorInfo(kiterrors.CodePrefixStateStore+kiterrors.CodeNotConfigured, nil).
Build()
}

func StateStoreNotFound(storeName string) error {
return kiterrors.NewBuilder(
codes.InvalidArgument, // TODO We should change this at some point. It should be codes.NotFound, but it will be a breaking change.
http.StatusBadRequest,
fmt.Sprintf("state store %s is not found", storeName),
"ERR_STATE_STORE_NOT_FOUND",
).
WithErrorInfo(kiterrors.CodePrefixStateStore+kiterrors.CodeNotFound, nil).
Build()
}

func StateStoreInvalidKeyName(storeName string, key string, msg string) error {
return kiterrors.NewBuilder(
codes.InvalidArgument,
Expand Down