@@ -15,6 +15,24 @@ import (
15
15
"github.com/smallnest/rpcx/log"
16
16
)
17
17
18
+ // RpcServiceError represents an error that is case by service implementation.
19
+ type RpcServiceInternalError struct {
20
+ Err string
21
+ Method string
22
+ Argv interface {}
23
+ stack string
24
+ }
25
+
26
+ // Error returns the error message.
27
+ func (e RpcServiceInternalError ) Error () string {
28
+ return fmt .Sprintf ("[service internal error]: %v, method: %s, argv: %+v, stack: %s" , e .Err , e .Method , e .Argv , e .stack )
29
+ }
30
+
31
+ // String returns the error message.
32
+ func (e RpcServiceInternalError ) String () string {
33
+ return e .Error ()
34
+ }
35
+
18
36
// Precompute the reflect type for error. Can't use error directly
19
37
// because Typeof takes an empty interface value. This is annoying.
20
38
var typeOfError = reflect .TypeOf ((* error )(nil )).Elem ()
@@ -357,8 +375,12 @@ func (s *service) call(ctx context.Context, mtype *methodType, argv, replyv refl
357
375
n := runtime .Stack (buf , false )
358
376
buf = buf [:n ]
359
377
360
- err = fmt .Errorf ("[service internal error]: %v, method: %s, argv: %+v, stack: %s" ,
361
- r , mtype .method .Name , argv .Interface (), buf )
378
+ err = & RpcServiceInternalError {
379
+ Err : fmt .Sprintf ("%v" , r ),
380
+ Method : mtype .method .Name ,
381
+ Argv : argv .Interface (),
382
+ stack : string (buf ),
383
+ }
362
384
log .Error (err )
363
385
}
364
386
}()
@@ -382,9 +404,12 @@ func (s *service) callForFunction(ctx context.Context, ft *functionType, argv, r
382
404
n := runtime .Stack (buf , false )
383
405
buf = buf [:n ]
384
406
385
- // log.Errorf("failed to invoke service: %v, stacks: %s", r, string(debug.Stack()))
386
- err = fmt .Errorf ("[service internal error]: %v, function: %s, argv: %+v, stack: %s" ,
387
- r , runtime .FuncForPC (ft .fn .Pointer ()), argv .Interface (), buf )
407
+ err = & RpcServiceInternalError {
408
+ Err : fmt .Sprintf ("%v" , r ),
409
+ Method : fmt .Sprintf ("%s" , runtime .FuncForPC (ft .fn .Pointer ())),
410
+ Argv : argv .Interface (),
411
+ stack : string (buf ),
412
+ }
388
413
log .Error (err )
389
414
}
390
415
}()
0 commit comments