Comments (1)
π€
Hello @SchopenhauerZhang! π
I'm Dosu, a friendly bot here to lend a helping hand with issues, questions, and contributions around the Kratos repository. While we're waiting for a human maintainer to review your issue, I'm here to help keep things moving. Looking forward to assisting you further!
To prevent error information from being ignored or overwritten when multiple errors occur in the Kratos Go microservices framework, you can use the multierror package. This package allows you to collect multiple errors and handle them all at once.
In the provided context, you can modify the unaryClientInterceptor and streamClientInterceptor functions to use multierror. Here's how you can do it:
import (
"github.com/hashicorp/go-multierror"
)
func unaryClientInterceptor(ms []middleware.Middleware, timeout time.Duration, filters []selector.NodeFilter) grpc.UnaryClientInterceptor {
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
// ...
var result *multierror.Error
_, err := h(ctx, req)
if err != nil {
result = multierror.Append(result, err)
}
return result.ErrorOrNil()
}
}
func streamClientInterceptor(filters []selector.NodeFilter) grpc.StreamClientInterceptor {
return func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) {
// ...
var result *multierror.Error
stream, err := streamer(ctx, desc, cc, method, opts...)
if err != nil {
result = multierror.Append(result, err)
}
return stream, result.ErrorOrNil()
}
}
In this code, we're using the Append function from the multierror package to collect all errors. The ErrorOrNil function is then used to return nil if there are no errors, or the errors themselves if there are any. This way, no error information will be ignored or overwritten.
The error handling mechanism in the Kratos Go microservices framework is primarily handled by the unaryClientInterceptor
and streamClientInterceptor
functions.
In the unaryClientInterceptor
function, the error handling is done by the invoker
function which is called inside the handler function h
. The invoker
function takes in the context, method, request, reply, client connection, and options as parameters and returns an error. If an error occurs during the invocation of the RPC, it will be returned by the invoker
function and subsequently by the unaryClientInterceptor
function.
h := func(ctx context.Context, req interface{}) (interface{}, error) {
// ...
return reply, invoker(ctx, method, req, reply, cc, opts...)
}
_, err := h(ctx, req)
return err
In the streamClientInterceptor
function, the error handling is done by the streamer
function. The streamer
function takes in the context, stream descriptor, client connection, method, and options as parameters and returns a client stream and an error. If an error occurs during the creation of the stream, it will be returned by the streamer
function and subsequently by the streamClientInterceptor
function.
return streamer(ctx, desc, cc, method, opts...)
These functions are used as interceptors for unary and streaming RPCs respectively. They allow for the interception of the RPC call, providing an opportunity to handle errors that may occur during the call.
Please let me know if you need further clarification or assistance.
Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a π if this is helpful and π if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
from kratos.
Related Issues (20)
- [Question] The pprof profile is not valid HOT 4
- [Feature] Replace `PGV` by `protovalidate` HOT 7
- [Question] Pubsub Implementation HOT 3
- [Question]How to print trace.id in log log HOT 8
- Request context canceled during graceful shutdown HOT 3
- [Question]How to do unit testing? HOT 5
- [Question] How to make kratos grpc transfer data larger than 4MB in size ? HOT 4
- The service startup error could not be printed correctly HOT 1
- [Question] The rules before and after loading the configuration file are inconsistent. Can they be improved? HOT 8
- How to print out all request routes, including intercepted or intercepted requests without content type HOT 3
- [Feature] Whether to consider supporting Filebeat access HOT 3
- proto. When the field of the query string passed by the front end is an empty string, the field parsed by the back end is nil. HOT 3
- Add a scheduled task server, dependency injection error HOT 3
- [Question] In the parameter verification section of the middleware in the official kratos documentation, the makefile instruction "Add the validate command in the Makefile" will report an error when copied. HOT 2
- logging.Server prints a wrong caller path HOT 1
- EncodeURL will ignore some fields if request message contains repeated custom message HOT 11
- [Question] Usage about selector peer HOT 4
- [Question] Why doesnβt Consul use the official watch for monitoring? HOT 4
- [Question] http API returns json parameter name not as expected HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kratos.