pkg/api/errors/README.md
This guide is intended for developers working on the Dapr code base, specifically for those updating the error handling to align with the gRPC richer error model. The goal is to standardize error responses across Dapr's services.
Currently, error handling in Dapr is a mix of predefined errors and dynamically constructed errors within the code.
/pkg/messages/predefined.go, but the new errors are located in /pkg/api/errors. These errors are standard and reused across various parts of the Dapr codebase. They provide a consistent error handling mechanism for common scenarios.As we move predefined errors to the rich error model and a new location (pkg/api/errors), the first step in updating to the new error model is to familiarize yourself with the existing error handling patterns, both predefined and dynamically constructed. This understanding will be crucial when replacing them with the richer error model aligned with gRPC standards.
/pkg/api/errors/.<building-block>.go.github.com/dapr/kit/errors.WithErrorInfo, WithResourceInfo to enrich error information.pkg/api/errors/state.go for a reference implementation. The following code snippet shows how to create a new error using the helper methods:func (s *StateStoreError) InvalidKeyName(key string, msg string) error {
return s.build(
errors.NewBuilder(
codes.InvalidArgument,
http.StatusBadRequest,
msg,
"ERR_MALFORMED_REQUEST",
).WithFieldViolation(key, msg),
errors.CodeIllegalKey,
nil,
)
}
/tests/integration/suite/daprd/state/grpc/errors.go and /tests/integration/suite/daprd/state/http/errors.go