From: Sergey Matveev Date: Mon, 2 Jun 2025 10:48:45 +0000 (+0300) Subject: Simplify RPC error transmission X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5be024ab16b1c7f1c1c516cbe9bba043233c20f0e8c74e61a3255ea53d12727a;p=keks.git Simplify RPC error transmission --- diff --git a/go/rpc/all_test.go b/go/rpc/all_test.go index b936002..624d160 100644 --- a/go/rpc/all_test.go +++ b/go/rpc/all_test.go @@ -99,7 +99,7 @@ func TestServer(t *testing.T) { if list[0] != uint64(i+1) { t.Fatal("bad id") } - if len(list[1].(map[string]any)) != 0 { + if len(list[1].(string)) != 0 { t.Fatal("has err", list[1]) } reply, err = keks.NewDecoderFromReader(cli, nil).Decode() diff --git a/go/rpc/client.go b/go/rpc/client.go index c556dc6..96faa93 100644 --- a/go/rpc/client.go +++ b/go/rpc/client.go @@ -69,23 +69,7 @@ func (cc *ClientCodec) ReadResponseHeader(resp *rpc.Response) (err error) { if !ok { return fmt.Errorf("keks/rpc: ReadResponseHeader: unknown id: %d", resp.Seq) } - e := list[1].(map[string]any) - if len(e) > 0 { - msg, ok := e["msg"] - if ok { - resp.Error = msg.(string) - if len(resp.Error) == 0 { - resp.Error = "unspecified" - } - } else { - code, ok := e["code"] - if ok { - resp.Error = fmt.Sprintf("code: %d", code.(uint64)) - } else { - resp.Error = "unspecified" - } - } - } + resp.Error = list[1].(string) return nil } diff --git a/go/rpc/err.go b/go/rpc/err.go deleted file mode 100644 index 51ca34c..0000000 --- a/go/rpc/err.go +++ /dev/null @@ -1,6 +0,0 @@ -package rpc - -type Error struct { - Msg *string `keks:"msg,omitempty"` - Code *uint64 `keks:"code,omitempty"` -} diff --git a/go/rpc/server.go b/go/rpc/server.go index 9e0aadc..1a9f936 100644 --- a/go/rpc/server.go +++ b/go/rpc/server.go @@ -78,11 +78,7 @@ func (sc *ServerCodec) WriteResponse(resp *rpc.Response, data any) (err error) { } delete(sc.pending, resp.Seq) sc.pendingM.Unlock() - e := Error{} - if resp.Error != "" { - e.Msg = &resp.Error - } - if _, err = keks.Encode(sc.conn, []any{id, e}, nil); err != nil { + if _, err = keks.Encode(sc.conn, []any{id, resp.Error}, nil); err != nil { return fmt.Errorf("keks/rpc: WriteResponse: %w", err) } if _, err = keks.Encode(sc.conn, data, nil); err != nil { diff --git a/spec/RPC b/spec/RPC index acc0186..e705624 100644 --- a/spec/RPC +++ b/spec/RPC @@ -6,8 +6,8 @@ Request object is a LIST followed by MAP with arbitrary values, maybe empty. "id" is a positive 64-bit integer, that must be unique during the whole session's connection. -Response object is also a LIST followed by MAP with arbitrary values. -Response's "id" must be the same as in corresponding request. Empty -error map means no error occurred. +Response object is also a LIST followed by MAP with arbitrary values, +corresponding error additional data. Response's "id" must be the same as +in corresponding request. Empty error string means no error occurred. << [schemas/rpc.tcl] diff --git a/tcl/schemas/rpc.tcl b/tcl/schemas/rpc.tcl index 505a6b3..6780272 100644 --- a/tcl/schemas/rpc.tcl +++ b/tcl/schemas/rpc.tcl @@ -7,10 +7,5 @@ req { resp { {field . {list} len=2} {field 0 {int} >0} {# id} - {field 1 {with err}} -} - -err { - {field msg {str} >0 optional} - {field code {int} >0 optional} + {field 1 {str}} {# error} }