fix: check Docker conflicts, push errors and RPC status by type, not message text (#1923)
This commit is contained in:
4 files changed
+7
-8
No files matched your search
@@ -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
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user