From b25676b61249aca4fbaf3585a537c4c8b1f6c154 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Fri, 13 Nov 2026 03:47:30 +1100 Subject: [PATCH] fix: check Docker conflicts, push errors and RPC status by type, not message text (#1923) --- go.mod | 2 +- internal/storage/storage.go | 7 +++---- internal/webui/workflows.go | 4 ++-- internal/worktree/worktree.go | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index b59d08080..b588b9ba5 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,6 @@ require ( github.com/cenkalti/backoff/v5 v5.0.3 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cloudflare/circl v1.6.5 // indirect - github.com/containerd/errdefs v1.0.0 // indirect github.com/containerd/errdefs/pkg v0.3.0 // indirect github.com/distribution/reference v0.6.0 // indirect github.com/docker/go-connections v0.8.2 // indirect @@ -69,6 +68,7 @@ require ( cel.dev/cel-go v0.33.2 github.com/BurntSushi/toml v1.6.0 github.com/cedar-policy/cedar-go v1.9.1 + github.com/containerd/errdefs v1.0.0 github.com/coreos/go-oidc/v3 v3.21.0 github.com/go-git/go-billy/v6 v6.0.0-beta.1 github.com/go-git/go-git/v6 v6.0.0-beta.1 diff --git a/internal/storage/storage.go b/internal/storage/storage.go index b214cdd23..f9aad8b18 100644 --- a/internal/storage/storage.go +++ b/internal/storage/storage.go @@ -23,6 +23,7 @@ import ( "strings" "time" + cerrdefs "github.com/containerd/errdefs" "github.com/moby/moby/api/types/mount" "github.com/moby/moby/client" ) @@ -255,10 +256,8 @@ func (d *DockerBackend) ensureVolume(ctx context.Context, name string, labels ma Labels: labels, }) if err != nil { - // TOCTOU: a concurrent caller may have created the volume between - // our inspect and create calls. Docker returns an error for - // duplicate volumes -- treat that as success. - if strings.Contains(err.Error(), "already exists") || strings.Contains(err.Error(), "already in use") { + // A concurrent caller may have created the volume after our inspect. + if cerrdefs.IsConflict(err) { return nil } return &ErrVolumeCreate{Volume: name, Cause: err} diff --git a/internal/webui/workflows.go b/internal/webui/workflows.go index b178f0fb0..7c0bc7aac 100644 --- a/internal/webui/workflows.go +++ b/internal/webui/workflows.go @@ -132,7 +132,7 @@ func (a *workflowsAPI) handleWorkRequest(w http.ResponseWriter, r *http.Request) } iface, code, err := a.workRequestInterface(r.Context(), request) if err != nil { - http.Error(w, err.Error(), code) + http.Error(w, status.Convert(err).Message(), code) return } if err := iface.CheckInputs(request.Inputs); err != nil { @@ -197,7 +197,7 @@ func (a *workflowsAPI) checkDraft(ctx context.Context, id, draft string) (task.W } if _, err := a.controlPlane.Command(ctx, &controlpb.CommandRequest{Kind: workflowDefinitionsKind, Command: "validate", ValueJson: value}); err != nil { if status.Code(err) == codes.InvalidArgument { - return task.WorkflowInterface{}, http.StatusBadRequest, errors.New(status.Convert(err).Message()) + return task.WorkflowInterface{}, http.StatusBadRequest, err } return task.WorkflowInterface{}, http.StatusServiceUnavailable, errors.New("workflow definitions unavailable") } diff --git a/internal/worktree/worktree.go b/internal/worktree/worktree.go index 89cf0e251..d7f1b588f 100644 --- a/internal/worktree/worktree.go +++ b/internal/worktree/worktree.go @@ -720,7 +720,7 @@ func (m *Manager) push(ctx context.Context, dir, branch, remoteURL string) error }) } err = publish() - if errors.Is(err, plumbing.ErrObjectNotFound) || err != nil && strings.Contains(err.Error(), plumbing.ErrObjectNotFound.Error()) { + if errors.Is(err, plumbing.ErrObjectNotFound) { // The clone borrows objects from the shared mirror; a damaged mirror // loses them. The forge still has every base object, so rebuild it. m.logger().WarnContext(ctx, "push hit a missing object, rebuilding the mirror", "branch", branch, "err", err)