@@ -28,7 +28,6 @@ import (
2828 "sync"
2929
3030 "github.com/go-logr/logr"
31- "github.com/pkg/errors"
3231 "golang.org/x/exp/maps"
3332
3433 "github.com/apecloud/kubeblocks/pkg/kbagent/proto"
@@ -85,17 +84,14 @@ func (s *actionService) HandleRequest(ctx context.Context, payload []byte) ([]by
8584 }
8685 resp , err := s .handleRequest (ctx , req )
8786 result := string (resp )
88- if err != nil {
89- result = err .Error ()
90- }
91- s .logger .Info ("Action Executed" , "action" , req .Action , "result" , result )
87+ s .logger .Info ("Action Executed" , "action" , req .Action , "result" , result , "err" , err )
9288 return s .encode (resp , err ), nil
9389}
9490
9591func (s * actionService ) decode (payload []byte ) (* proto.ActionRequest , error ) {
9692 req := & proto.ActionRequest {}
9793 if err := json .Unmarshal (payload , req ); err != nil {
98- return nil , errors . Wrapf ( proto . ErrBadRequest , " unmarshal action request error: %s " , err . Error () )
94+ return nil , fmt . Errorf ( "%w: unmarshal action request error: %w " , proto . ErrBadRequest , err )
9995 }
10096 return req , nil
10197}
@@ -114,11 +110,11 @@ func (s *actionService) encode(out []byte, err error) []byte {
114110
115111func (s * actionService ) handleRequest (ctx context.Context , req * proto.ActionRequest ) ([]byte , error ) {
116112 if _ , ok := s .actions [req .Action ]; ! ok {
117- return nil , errors . Wrapf ( proto . ErrNotDefined , "% s is not defined" , req .Action )
113+ return nil , fmt . Errorf ( "%w: % s is not defined", proto . ErrNotDefined , req .Action )
118114 }
119115 action := s .actions [req .Action ]
120116 if action .Exec == nil {
121- return nil , errors . Wrap ( proto . ErrNotImplemented , " only exec action is supported" )
117+ return nil , fmt . Errorf ( "%w: only exec action is supported", proto . ErrNotImplemented )
122118 }
123119 // HACK: pre-check for the reconfigure action
124120 if err := checkReconfigure (ctx , req ); err != nil {
@@ -154,8 +150,5 @@ func (s *actionService) handleExecActionNonBlocking(ctx context.Context, req *pr
154150 return nil , proto .ErrInProgress
155151 }
156152 delete (s .runningActions , req .Action )
157- if (* result ).err != nil {
158- return nil , (* result ).err
159- }
160- return (* result ).stdout .Bytes (), nil
153+ return (* result ).stdout .Bytes (), wrapExecError ((* result ).err , (* result ).stderr )
161154}
0 commit comments