Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

fix: an unresolvable ref answers 500 retryable:true with the recovery matcher's internal score, while the same ref on a declared submit answers 404 (PIN-238)

Luigi Agostif571cc465fb3
diff --git a/internal/bridge/action_form.go b/internal/bridge/action_form.go
index 04c29931..4996a113 100644
--- a/internal/bridge/action_form.go
+++ b/internal/bridge/action_form.go
@@ -90,7 +90,7 @@ func (b *Bridge) actionSelect(ctx context.Context, req ActionRequest) (map[strin
}
return map[string]any{"selected": val}, SelectByNodeID(ctx, int64(node.BackendNodeID), val)
}
- return nil, fmt.Errorf("need selector or ref")
+ return nil, NewInvalidActionRequestError("need selector or ref")
}
func (b *Bridge) actionCheck(ctx context.Context, req ActionRequest) (map[string]any, error) {
@@ -112,7 +112,7 @@ func checkUncheck(ctx context.Context, req ActionRequest, wantChecked bool) (map
} else if req.Selector != "" {
resolveJS = req.Selector
} else {
- return nil, fmt.Errorf("need selector, ref, or nodeId")
+ return nil, NewInvalidActionRequestError("need selector, ref, or nodeId")
}
var objectID string
diff --git a/internal/bridge/action_invalid_request_test.go b/internal/bridge/action_invalid_request_test.go
new file mode 100644
index 00000000..afb61d84
--- /dev/null
+++ b/internal/bridge/action_invalid_request_test.go
@@ -0,0 +1,41 @@
+package bridge
+
+import (
+ "context"
+ "errors"
+ "sort"
+ "strings"
+ "testing"
+
+ "github.com/pinchtab/pinchtab/internal/config"
+)
+
+// A request naming no target is the caller having omitted a required argument, so every
+// action that refuses one must say so with the sentinel — the endpoint answers 400 from that
+// and from nothing else, and a plain fmt.Errorf lands in the catch-all that reports a typo as
+// a server fault the caller should retry. The census is over the whole registry rather than
+// the kinds this card measured: a new action refusing the same way is covered without a
+// second edit.
+func TestATargetlessActionIsRefusedWithTheInvalidRequestSentinel(t *testing.T) {
+ b := New(context.TODO(), nil, &config.RuntimeConfig{})
+ if len(b.Actions) == 0 {
+ t.Fatal("the action registry is empty; this census would pass vacuously")
+ }
+
+ var refused []string
+ for kind, action := range b.Actions {
+ _, err := action(context.Background(), ActionRequest{})
+ if err == nil || !strings.Contains(err.Error(), "need selector") {
+ continue
+ }
+ refused = append(refused, kind)
+ if !errors.Is(err, ErrInvalidActionRequest) {
+ t.Errorf("%s refuses a targetless request with a bare error (%v); the endpoint cannot tell it from a browser fault and answers 500 retryable", kind, err)
+ }
+ }
+
+ sort.Strings(refused)
+ if len(refused) < 5 {
+ t.Fatalf("only %v refused a targetless request; the census is no longer reaching the refusals it exists to check", refused)
+ }
+}
diff --git a/internal/bridge/action_pointer.go b/internal/bridge/action_pointer.go
index 5616fede..e152d208 100644
--- a/internal/bridge/action_pointer.go
+++ b/internal/bridge/action_pointer.go
@@ -329,7 +329,7 @@ func (b *Bridge) actionClick(ctx context.Context, req ActionRequest) (result map
} else if req.HasXY {
err = clickByCoordinateAction(clickCtx, req.X, req.Y, req.Modifiers)
} else {
- resultCh <- clickResult{err: fmt.Errorf("need selector, ref, nodeId, or x/y coordinates")}
+ resultCh <- clickResult{err: NewInvalidActionRequestError("need selector, ref, nodeId, or x/y coordinates")}
return
}
resultCh <- clickResult{err: err}
@@ -418,7 +418,7 @@ func (b *Bridge) actionDoubleClick(ctx context.Context, req ActionRequest) (resu
}
err = DoubleClickByCoordinate(ctx, req.X, req.Y)
} else {
- return nil, fmt.Errorf("need selector, ref, nodeId, or x/y coordinates")
+ return nil, NewInvalidActionRequestError("need selector, ref, nodeId, or x/y coordinates")
}
if err != nil {
return nil, err
@@ -443,7 +443,7 @@ func (b *Bridge) actionHover(ctx context.Context, req ActionRequest) (map[string
if req.HasXY {
return map[string]any{"hovered": true}, HoverByCoordinate(ctx, req.X, req.Y)
}
- return nil, fmt.Errorf("need selector, ref, nodeId, or x/y coordinates")
+ return nil, NewInvalidActionRequestError("need selector, ref, nodeId, or x/y coordinates")
}
func (b *Bridge) actionHumanizedHover(ctx context.Context, req ActionRequest) (map[string]any, error) {
@@ -460,7 +460,7 @@ func (b *Bridge) actionHumanizedHover(ctx context.Context, req ActionRequest) (m
case req.HasXY:
err = hoverCoordinateAction(ctx, req.X, req.Y)
default:
- return nil, fmt.Errorf("need selector, ref, nodeId, or x/y coordinates")
+ return nil, NewInvalidActionRequestError("need selector, ref, nodeId, or x/y coordinates")
}
if err != nil {
return nil, err
@@ -494,7 +494,7 @@ func pointerTargetRequiredError(req ActionRequest, allowCurrent bool) error {
if allowCurrent && strings.TrimSpace(req.TabID) != "" {
return fmt.Errorf("no pointer position known for tab %s; move pointer first or provide selector, ref, nodeId, or x/y coordinates", req.TabID)
}
- return fmt.Errorf("need selector, ref, nodeId, or x/y coordinates")
+ return NewInvalidActionRequestError("need selector, ref, nodeId, or x/y coordinates")
}
func (b *Bridge) pointerCoordinatesFromRequest(ctx context.Context, req ActionRequest, allowCurrent bool) (float64, float64, error) {
@@ -719,7 +719,7 @@ func dragPointFor(ctx context.Context, end dragEnd) (float64, float64, error) {
case end.hasPoint:
return end.x, end.y, nil
}
- return 0, 0, fmt.Errorf("need selector, ref, nodeId, or coordinates")
+ return 0, 0, NewInvalidActionRequestError("need selector, ref, nodeId, or coordinates")
}
func (r ActionRequest) hasDragDestination() bool {
@@ -746,7 +746,7 @@ func (b *Bridge) actionHumanizedClick(ctx context.Context, req ActionRequest) (r
auto.prepareNode(ctx, int64(node.BackendNodeID))
}
default:
- return nil, fmt.Errorf("need selector, ref, or nodeId")
+ return nil, NewInvalidActionRequestError("need selector, ref, or nodeId")
}
// If the caller expects this click to open a native JS dialog, arm a
@@ -813,5 +813,5 @@ func (b *Bridge) actionScrollIntoView(ctx context.Context, req ActionRequest) (m
}
return ScrollIntoViewAndGetBox(ctx, nid)
}
- return nil, fmt.Errorf("need selector or ref")
+ return nil, NewInvalidActionRequestError("need selector or ref")
}
diff --git a/internal/bridge/action_text.go b/internal/bridge/action_text.go
index 40e1417f..0719a3b5 100644
--- a/internal/bridge/action_text.go
+++ b/internal/bridge/action_text.go
@@ -33,7 +33,7 @@ func (b *Bridge) actionType(ctx context.Context, req ActionRequest) (map[string]
if req.NodeID > 0 {
return textEntryResult("typed", req.Text), TypeByNodeID(ctx, req.NodeID, req.Text)
}
- return nil, fmt.Errorf("need selector or ref")
+ return nil, NewInvalidActionRequestError("need selector or ref")
}
func (b *Bridge) actionFill(ctx context.Context, req ActionRequest) (map[string]any, error) {
@@ -60,7 +60,7 @@ func (b *Bridge) actionFill(ctx context.Context, req ActionRequest) (map[string]
}
return finishFill(ctx, result, req.Submit)
}
- return nil, fmt.Errorf("need selector or ref")
+ return nil, NewInvalidActionRequestError("need selector or ref")
}
func finishFill(ctx context.Context, result map[string]any, submit bool) (map[string]any, error) {
@@ -153,7 +153,7 @@ func (b *Bridge) actionHumanizedType(ctx context.Context, req ActionRequest) (ma
return nil, err
}
} else {
- return nil, fmt.Errorf("need selector, ref, or nodeId")
+ return nil, NewInvalidActionRequestError("need selector, ref, or nodeId")
}
actions := Type(req.Text, req.Fast)
diff --git a/internal/handlers/action_execution.go b/internal/handlers/action_execution.go
index 9607a55a..d8f3bd14 100644
--- a/internal/handlers/action_execution.go
+++ b/internal/handlers/action_execution.go
@@ -21,6 +21,30 @@ const (
var readTopmostSubmitModal = bridge.TopmostModalNodeIDInFrame
+// takeASnapshotFirst is the one spelling of the only advice that re-resolves an absent
+// target. Every refusal that carries it composes it from here, so the four copies the
+// endpoint used to format cannot drift apart again.
+const takeASnapshotFirst = "take a /snapshot first"
+
+// ErrTargetNotFound is the one owner of "this target cannot be resolved" — a stale ref
+// recovery could not heal, a ref that never existed, a drag destination that is gone. Every
+// producer wraps it and the endpoint answers one 404 with the remedy, so the arm keys on the
+// sentinel rather than on the wording. Retrying is futile by construction: the target is
+// absent, not busy.
+var ErrTargetNotFound = errors.New("not found")
+
+// targetNotFound names WHAT is missing ("ref e2", "drag destination e7"). The recovery
+// matcher's threshold and score stay out of it — they describe the matcher's internals,
+// not anything the caller can act on, and ride in the recovery record the endpoint puts
+// in details.
+func targetNotFound(subject string) error {
+ return fmt.Errorf("%s %w - %s", subject, ErrTargetNotFound, takeASnapshotFirst)
+}
+
+func refNotFound(ref string) error {
+ return targetNotFound("ref " + ref)
+}
+
type submitStateSnapshot struct {
URL string `json:"url"`
DialogOpen bool `json:"dialogOpen"`
@@ -157,7 +181,7 @@ func (h *Handlers) cacheActionIntent(tabID string, req bridge.ActionRequest) {
// Submit-detection is a PROXY for non-idempotency, not a solution to it. A delete link is
// as dangerous and the DOM cannot say so; a policy for non-idempotent clicks at large is a
// separate decision and this refusal does not claim to cover the class.
-var ErrStaleSubmitTarget = errors.New("ref is stale and its target submits a form; take a /snapshot first and click the fresh ref")
+var ErrStaleSubmitTarget = fmt.Errorf("ref is stale and its target submits a form; %s and click the fresh ref", takeASnapshotFirst)
// submitControlJS reports whether the node is the control that submits a form. A var so a
// test can stub it: the guard's own effect is only visible against a real page, and the
@@ -253,7 +277,7 @@ func (h *Handlers) executeActionResilient(ctx context.Context, req *bridge.Actio
if errors.Is(recErr, bridge.ErrUnexpectedNavigation) {
return nil, "", &rr, recErr
}
- return nil, "", &rr, fmt.Errorf("ref %s not found and recovery failed: %w", req.Ref, recErr)
+ return nil, "", &rr, refNotFound(req.Ref)
}
return recRes, "", &rr, nil
}
@@ -369,7 +393,7 @@ func (h *Handlers) refreshActionSecondaryTargets(ctx context.Context, tabID stri
}
}
}
- return fmt.Errorf("drag destination %s not found - take a /snapshot first", toSelector)
+ return targetNotFound("drag destination " + toSelector)
}
// uniqueNodeForDescriptor returns the one node matching the descriptor's role and
diff --git a/internal/handlers/action_ref_not_found_test.go b/internal/handlers/action_ref_not_found_test.go
new file mode 100644
index 00000000..0d6d13ce
--- /dev/null
+++ b/internal/handlers/action_ref_not_found_test.go
@@ -0,0 +1,218 @@
+package handlers
+
+import (
+ "context"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/pinchtab/pinchtab/internal/bridge"
+ "github.com/pinchtab/pinchtab/internal/config"
+)
+
+// A nodeId keeps selector resolution out of CDP so the endpoint can be driven with the
+// package mock; the ref rides along because it is what the refusal has to name.
+func targetedActionBody(kind, extra string) string {
+ return fmt.Sprintf(`{"kind":%q,"ref":"e99","nodeId":42,"tabId":"tab1"%s}`, kind, extra)
+}
+
+func postTargetedAction(t *testing.T, kind, extra string, executeErr error) (*httptest.ResponseRecorder, map[string]any) {
+ t.Helper()
+ mb := &mockBridge{
+ availableActions: []string{kind},
+ executeActionErr: executeErr,
+ }
+ h := New(mb, &config.RuntimeConfig{ActionTimeout: time.Second}, nil, nil, nil)
+ w := httptest.NewRecorder()
+ h.HandleAction(w, httptest.NewRequest("POST", "/action", strings.NewReader(targetedActionBody(kind, extra))))
+ return w, decodeJSONMap(t, w.Body.Bytes())
+}
+
+// The reported defect: the same unresolvable ref answered 404 with the remedy on a declared
+// submit and 500 retryable:true with the recovery matcher's score on every other verb. It is
+// the same fact about the same request, so it is the same answer.
+func TestAnUnresolvableRefIsANotFoundForEveryVerb(t *testing.T) {
+ for _, kind := range []string{bridge.ActionClick, bridge.ActionHover, bridge.ActionType, bridge.ActionFocus, bridge.ActionCheck} {
+ t.Run(kind, func(t *testing.T) {
+ w, body := postTargetedAction(t, kind, "", refNotFound("e99"))
+
+ if w.Code != http.StatusNotFound {
+ t.Errorf("status = %d, want %d — the ref is absent, which is the caller's request being wrong, not the server failing: %s", w.Code, http.StatusNotFound, w.Body.String())
+ }
+ if body["code"] != "ref_not_found" {
+ t.Errorf("code = %v, want ref_not_found", body["code"])
+ }
+ if retryable, present := body["retryable"]; present && retryable != false {
+ t.Errorf("retryable = %v; retrying an absent ref can never succeed, so advertising a retry sends the caller into a loop that cannot end", retryable)
+ }
+ if got, want := body["error"], "ref e99 not found - take a /snapshot first"; got != want {
+ t.Errorf("error = %q, want %q — the remedy is the whole value of this refusal", got, want)
+ }
+ })
+ }
+}
+
+// The card's third case: a click naming nothing to click is the caller having omitted a
+// required argument. The bridge refuses it with the sentinel (its own census pins that), and
+// the endpoint answers the status an omitted argument deserves rather than a server fault
+// the caller is told to retry.
+func TestAClickNamingNothingToClickIsACallerError(t *testing.T) {
+ mb := &mockBridge{
+ availableActions: []string{bridge.ActionClick},
+ executeActionErr: bridge.NewInvalidActionRequestError("need selector, ref, nodeId, or x/y coordinates"),
+ }
+ h := New(mb, &config.RuntimeConfig{ActionTimeout: time.Second}, nil, nil, nil)
+ w := httptest.NewRecorder()
+ h.HandleAction(w, httptest.NewRequest("POST", "/action", strings.NewReader(`{"kind":"click","tabId":"tab1"}`)))
+ body := decodeJSONMap(t, w.Body.Bytes())
+
+ if w.Code != http.StatusBadRequest {
+ t.Errorf("status = %d, want %d: %s", w.Code, http.StatusBadRequest, w.Body.String())
+ }
+ if body["code"] != "invalid_action_request" {
+ t.Errorf("code = %v, want invalid_action_request", body["code"])
+ }
+ if body["retryable"] == true {
+ t.Error("an omitted argument was advertised as retryable; the identical body is unsatisfiable on every attempt")
+ }
+ if got, _ := body["error"].(string); !strings.Contains(got, "need selector, ref, nodeId, or x/y coordinates") {
+ t.Errorf("error = %q, which does not say what the caller left out", got)
+ }
+}
+
+// The submit path and the ordinary one word the same fact identically because ONE site
+// spells the remedy. Four sites used to format it, which is how they came to disagree about
+// the status while agreeing about the words. A new copy reds here by file and line, and the
+// count is checked against a floor so a renamed constant cannot pass the guard vacuously.
+func TestOneSiteSpellsTheSnapshotRemedy(t *testing.T) {
+ entries, err := os.ReadDir(".")
+ if err != nil {
+ t.Fatal(err)
+ }
+ var sites []string
+ for _, entry := range entries {
+ name := entry.Name()
+ if !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") {
+ continue
+ }
+ src, readErr := os.ReadFile(name)
+ if readErr != nil {
+ t.Fatal(readErr)
+ }
+ for i, line := range strings.Split(string(src), "\n") {
+ if strings.Contains(line, `take a /snapshot first`) {
+ sites = append(sites, fmt.Sprintf("%s:%d %s", name, i+1, strings.TrimSpace(line)))
+ }
+ }
+ }
+
+ if len(sites) != 1 {
+ t.Fatalf("the snapshot remedy is spelled at %d sites; one owner or they drift:\n %s", len(sites), strings.Join(sites, "\n "))
+ }
+ if !strings.Contains(sites[0], "takeASnapshotFirst =") {
+ t.Errorf("the one site is not the constant every refusal composes from: %s", sites[0])
+ }
+}
+
+// Both sentences the endpoint answers carry the remedy, so the constant is load-bearing
+// rather than merely present.
+func TestBothRefusalsCarryTheSnapshotRemedy(t *testing.T) {
+ for name, err := range map[string]error{
+ "an absent ref": refNotFound("e99"),
+ "a stale submit": ErrStaleSubmitTarget,
+ "a gone drag drop": targetNotFound("drag destination e7"),
+ } {
+ if !strings.Contains(err.Error(), takeASnapshotFirst) {
+ t.Errorf("%s refuses without the only advice that fixes it: %s", name, err.Error())
+ }
+ }
+ if errors.Is(ErrStaleSubmitTarget, ErrTargetNotFound) {
+ t.Error("the stale-submit refusal now matches the absent-target arm, which would swallow its dispatch state and its own code")
+ }
+}
+
+// The matcher's threshold and score describe how recovery searched, not what the caller can
+// do. They stay in the recovery record, which the refusal carries in details.
+func TestTheRecoveryMatchersInternalsStayOutOfTheCallerFacingError(t *testing.T) {
+ mb := &mockBridge{availableActions: []string{bridge.ActionHover}}
+ h := New(mb, &config.RuntimeConfig{ActionTimeout: time.Second}, nil, nil, nil)
+ req := bridge.ActionRequest{Kind: bridge.ActionHover, Ref: "e99", TabID: "tab1"}
+
+ _, _, rr, err := h.executeActionResilient(context.Background(), &req, h.Config, "tab1", true)
+
+ if !errors.Is(err, ErrTargetNotFound) {
+ t.Fatalf("exhausted recovery returned %v, which no arm classifies as an absent target", err)
+ }
+ for _, leak := range []string{"threshold", "best:", "recovery failed", "cached intent"} {
+ if strings.Contains(err.Error(), leak) {
+ t.Errorf("the caller-facing error carries the matcher's internals (%q): %s", leak, err.Error())
+ }
+ }
+ if rr == nil {
+ t.Fatal("no recovery record was published, so the diagnosis the message dropped is nowhere")
+ }
+ if !strings.Contains(rr.Error, "e99") {
+ t.Errorf("the recovery record does not say why recovery failed: %+v", rr)
+ }
+}
+
+// retryable now answers the question it names. It used to be !submitClick — whether the
+// caller declared a submit, which says nothing about the failure.
+func TestRetryableIsDerivedFromTheFailureNotFromTheVerb(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ err error
+ mayHaveLanded bool
+ wantRetryable bool
+ wantBecauseItWere string
+ }{
+ {
+ name: "an absent target",
+ err: refNotFound("e99"),
+ wantBecauseItWere: "an absent ref stays absent however often it is asked for",
+ },
+ {
+ name: "an absent drag destination",
+ err: targetNotFound("drag destination e7"),
+ wantBecauseItWere: "the destination is gone, and the identical drag has nowhere to land",
+ },
+ {
+ name: "a body the action cannot satisfy",
+ err: bridge.NewInvalidActionRequestError("need selector, ref, nodeId, or x/y coordinates"),
+ wantBecauseItWere: "the same body is unsatisfiable on every attempt",
+ },
+ {
+ name: "a transport failure",
+ err: errors.New("dispatch mouse event: websocket closed"),
+ wantRetryable: true,
+ wantBecauseItWere: "a dropped connection is exactly what the flag exists for",
+ },
+ {
+ name: "a transport failure after a dispatch that may have landed",
+ err: errors.New("dispatch mouse event: websocket closed"),
+ mayHaveLanded: true,
+ wantBecauseItWere: "repeating a submit that may already have posted is worse than failing",
+ },
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ if got := actionFailureIsRetryable(tc.err, tc.mayHaveLanded); got != tc.wantRetryable {
+ t.Errorf("retryable = %v, want %v — %s", got, tc.wantRetryable, tc.wantBecauseItWere)
+ }
+ })
+ }
+}
+
+func decodeJSONMap(t *testing.T, raw []byte) map[string]any {
+ t.Helper()
+ var out map[string]any
+ if err := json.Unmarshal(raw, &out); err != nil {
+ t.Fatalf("decode response: %v body=%s", err, raw)
+ }
+ return out
+}
diff --git a/internal/handlers/actions.go b/internal/handlers/actions.go
index 8958dab2..f1ba2624 100644
--- a/internal/handlers/actions.go
+++ b/internal/handlers/actions.go
@@ -23,6 +23,7 @@ import (
"github.com/pinchtab/pinchtab/internal/routes"
"github.com/pinchtab/pinchtab/internal/selector"
"github.com/pinchtab/pinchtab/internal/session"
+ "github.com/pinchtab/semantic/recovery"
)
func resolveOwner(r *http.Request, fallback string) string {
@@ -102,6 +103,32 @@ func staleSubmitTargetDetails() map[string]any {
return details
}
+// writeTargetNotFound is the one response for a target that cannot be resolved, whichever
+// path exhausted it. 404 rather than 500 because the request named something that is not
+// there; retryable is absent because an absent target stays absent. The recovery record
+// carries the matcher's score and threshold when there is one — diagnosis belongs in
+// details, never in the sentence a caller reads as the reason.
+func writeTargetNotFound(w http.ResponseWriter, err error, rr *recovery.RecoveryResult) {
+ details := map[string]any{"dispatched": false}
+ if rr != nil {
+ details["recovery"] = rr
+ }
+ httpx.ErrorCode(w, http.StatusNotFound, "ref_not_found", err.Error(), false, details)
+}
+
+// actionFailureIsRetryable answers the only question the flag promises: could repeating the
+// IDENTICAL request plausibly succeed. It used to be !submitClick, which says whether the
+// caller declared a submit and nothing about the failure, so every unresolvable ref and
+// every unsatisfiable body was advertised as worth retrying. A permanently unsatisfiable
+// failure never is, and a dispatch that may already have landed must not be repeated
+// whatever the error was.
+func actionFailureIsRetryable(err error, dispatchMayHaveLanded bool) bool {
+ if err == nil || dispatchMayHaveLanded {
+ return false
+ }
+ return !errors.Is(err, ErrTargetNotFound) && !errors.Is(err, bridge.ErrInvalidActionRequest)
+}
+
const navigationChangedHint = "The action navigated the page, which the guard reports unless the request declares it: set waitNav true to wait for the navigation, or submit true when the click submits a form. From the CLI those are --wait-nav and --submit."
// The ref stays a placeholder: this guard reports on an action it did not receive the ref
@@ -547,7 +574,7 @@ func (h *Handlers) HandleAction(w http.ResponseWriter, r *http.Request) {
if destinationResolution.refMissing {
h.refreshRefCache(tCtx, resolvedTabID)
if err := h.refreshActionSecondaryTargets(tCtx, resolvedTabID, &req); err != nil {
- httpx.Error(w, 404, err)
+ writeTargetNotFound(w, err, nil)
return
}
} else if req.ToSelector != "" && req.ToNodeID != 0 && h.Recovery != nil {
@@ -558,7 +585,7 @@ func (h *Handlers) HandleAction(w http.ResponseWriter, r *http.Request) {
refMissing := selectorResolution.refMissing
submitClick := bridge.IsSubmitClick(req.Kind, req)
if submitClick && refMissing {
- httpx.ErrorCode(w, http.StatusNotFound, "submit_target_not_found", fmt.Sprintf("ref %s not found - take a /snapshot first", req.Ref), false, staleSubmitTargetDetails())
+ httpx.ErrorCode(w, http.StatusNotFound, "submit_target_not_found", refNotFound(req.Ref).Error(), false, staleSubmitTargetDetails())
return
}
if submitClick && req.NodeID <= 0 {
@@ -572,8 +599,8 @@ func (h *Handlers) HandleAction(w http.ResponseWriter, r *http.Request) {
h.cacheActionIntent(resolvedTabID, req)
}
- if refMissing && (req.Ref == "" || h.Recovery == nil) {
- httpx.Error(w, 404, fmt.Errorf("ref %s not found - take a /snapshot first", req.Ref))
+ if refMissing && h.Recovery == nil {
+ writeTargetNotFound(w, refNotFound(req.Ref), nil)
return
}
@@ -631,7 +658,7 @@ func (h *Handlers) HandleAction(w http.ResponseWriter, r *http.Request) {
}
if errors.Is(actionErr, ErrStaleSubmitTarget) {
httpx.ErrorCode(w, http.StatusNotFound, "submit_target_not_found",
- fmt.Sprintf("ref %s not found - take a /snapshot first", req.Ref), false, staleSubmitTargetDetails())
+ refNotFound(req.Ref).Error(), false, staleSubmitTargetDetails())
return
}
if errors.Is(actionErr, bridge.ErrUnexpectedNavigation) {
@@ -654,15 +681,19 @@ func (h *Handlers) HandleAction(w http.ResponseWriter, r *http.Request) {
writeDialogBlocked(w, resolvedTabID, dialog, message)
return
}
- retryable := !submitClick
+ if errors.Is(actionErr, ErrTargetNotFound) {
+ writeTargetNotFound(w, actionErr, recoveryResult)
+ return
+ }
+ dispatchMayHaveLanded := submitClick
var details map[string]any
- if submitClick {
+ if dispatchMayHaveLanded {
details = map[string]any{
"dispatch": "unconfirmed",
"doNotRetry": true,
}
}
- h.errorCodeWithCrashContext(w, 500, "action_failed", fmt.Sprintf("action %s: %v", req.Kind, actionErr), retryable, details)
+ h.errorCodeWithCrashContext(w, 500, "action_failed", fmt.Sprintf("action %s: %v", req.Kind, actionErr), actionFailureIsRetryable(actionErr, dispatchMayHaveLanded), details)
return
}
@@ -852,7 +883,7 @@ func (h *Handlers) runMultiStepActionTail(
cancel()
*results = append(*results, actionResult{
Index: index, Success: false,
- Error: fmt.Sprintf("ref %s not found - take a /snapshot first", step.Ref),
+ Error: refNotFound(step.Ref).Error(),
})
return ctx, resolvedTabID, stopOnError
}