S8 unread-away: Unread of a state and a view, the away answers, the start's phase
Builds: design 47 H2 H-A-708 (1) (2), H-A-717 (DQ-54, DQ-58)
This commit is contained in:
@@ -203,6 +203,30 @@ func TestACallIsAskedAgainOnlyWhenItReachedNoOne(t *testing.T) {
|
||||
t.Errorf("the holder read the ask %q, want %q, and none once its handler ended", read, ask)
|
||||
}
|
||||
}
|
||||
// Design 47 H2 H-A-708 (2): a handler's `away` fault is answered as §776's `away` (error-kind, part, words) and read back
|
||||
// by the caller as the transport fault; a plain refusal names no kind.
|
||||
for _, row := range []struct {
|
||||
err error
|
||||
kind string
|
||||
part string
|
||||
fault bool
|
||||
}{
|
||||
{&busretry.Away{Part: "the trunk's revision 512", Words: "not read yet since 23:35:40"}, "away", "the trunk's revision 512", true},
|
||||
{fmt.Errorf("reading: %w", &busretry.Away{Part: "the state seat-definitions", Words: "w"}), "away", "the state seat-definitions", true},
|
||||
{errors.New("refused"), "", "", false},
|
||||
} {
|
||||
body := c.answerBody(askMsg("mesh.seat.mesh-catalog.tool.revision", []byte(`{}`), ""), "mesh.seat.mesh-catalog.tool.revision",
|
||||
func(string, json.RawMessage, bool) (any, *approval.Held, error) { return nil, nil, row.err })
|
||||
var got struct{ Kind, Part string }
|
||||
var raw map[string]any
|
||||
_ = json.Unmarshal(body, &raw)
|
||||
got.Kind, _ = raw["error-kind"].(string)
|
||||
got.Part, _ = raw["part"].(string)
|
||||
away := busretry.AwayIn(body)
|
||||
if got.Kind != row.kind || got.Part != row.part || (away != nil) != row.fault || (away != nil && busretry.Fault(away) != true) {
|
||||
t.Errorf("%v answered %s", row.err, body)
|
||||
}
|
||||
}
|
||||
// Design 47 H2 §775, H-A-405: a kept chunked call (CallChunksKept, CallFileKept) asks its verb through the kept-call
|
||||
// form, carries its one ask id on every chunk's acknowledgement, and past its bound ends with the kept call's words.
|
||||
send := buscalls.SeatChunks{Seat: "node-build-go", Verb: "output", Call: "c1"}
|
||||
|
||||
+17
-2
@@ -2,6 +2,7 @@ package process
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/approval"
|
||||
"git.novox.be/novox/mesh-sdk/go/busretry"
|
||||
"git.novox.be/novox/mesh-sdk/go/calladdress"
|
||||
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
||||
)
|
||||
@@ -177,6 +179,11 @@ func AskOf(body json.RawMessage) string {
|
||||
|
||||
// answerCall runs h for one call and replies {result, error, node}; a panic in h is the call's error, never silence.
|
||||
func (c *Conn) answerCall(msg *nats.Msg, pattern string, h heldHandler) {
|
||||
_ = msg.Respond(c.answerBody(msg, pattern, h))
|
||||
}
|
||||
|
||||
// answerBody is the reply answerCall sends.
|
||||
func (c *Conn) answerBody(msg *nats.Msg, pattern string, h heldHandler) []byte {
|
||||
caller := ""
|
||||
if strings.HasSuffix(pattern, ".*") {
|
||||
caller = userOfToken(msg.Subject[strings.LastIndex(msg.Subject, ".")+1:])
|
||||
@@ -184,7 +191,11 @@ func (c *Conn) answerCall(msg *nats.Msg, pattern string, h heldHandler) {
|
||||
var reply struct {
|
||||
Result any `json:"result,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Node string `json:"node,omitempty"`
|
||||
// ErrorKind, Part and Words are an answer of the kind away (design 47 H2 §776, H-A-708 (2)).
|
||||
ErrorKind string `json:"error-kind,omitempty"`
|
||||
Part string `json:"part,omitempty"`
|
||||
Words string `json:"words,omitempty"`
|
||||
Node string `json:"node,omitempty"`
|
||||
// Held is a kept call's answer (design 47 G §677; lead answer A-244).
|
||||
Held *approval.Held `json:"held,omitempty"`
|
||||
}
|
||||
@@ -205,6 +216,10 @@ func (c *Conn) answerCall(msg *nats.Msg, pattern string, h heldHandler) {
|
||||
switch {
|
||||
case err != nil:
|
||||
reply.Error = err.Error()
|
||||
var away *busretry.Away
|
||||
if errors.As(err, &away) {
|
||||
reply.ErrorKind, reply.Part, reply.Words = busretry.ErrorKindAway, away.Part, away.Words
|
||||
}
|
||||
case held != nil:
|
||||
reply.Held = held
|
||||
case result == nil:
|
||||
@@ -218,5 +233,5 @@ func (c *Conn) answerCall(msg *nats.Msg, pattern string, h heldHandler) {
|
||||
if err != nil {
|
||||
body, _ = json.Marshal(map[string]string{"error": "the answer is not JSON: " + err.Error(), "node": c.account.Node})
|
||||
}
|
||||
_ = msg.Respond(body)
|
||||
return body
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user