docker/cli · warning · cancelledErr

builder prune has been cancelled

Error message

builder prune has been cancelled

What it means

In runPrune (cli/command/builder/prune.go:71) for 'docker builder prune', when --force/-f is not set, the CLI prompts for confirmation. If the user answers 'no', the function returns cancelledErr{errors.New("builder prune has been cancelled")} at line 84. cancelledErr implements the containerd errdefs Cancelled() marker interface, so callers can detect it as an intentional cancellation rather than a hard failure.

Solutions

  1. Pass --force (-f) to skip the prompt when pruning non-interactively.
  2. If the cancellation is expected behavior in your flow, detect it via the errdefs Cancelled interface rather than treating it as a fatal error.
  3. Pipe 'y' to stdin, or use `yes y | docker builder prune` for interactive automation (prefer -f instead).

Example fix

# before (prompts and you answer no)
docker builder prune
# after — skip the confirmation
docker builder prune -f
Defensive patterns

Strategy: type-guard

Validate before calling

// Non-interactive invocation: pass -f to avoid the prompt entirely.
// (No code path needed; flag-based.)

Type guard

// cancelledErr implements the containerd errdefs Cancelled marker interface.
// Detect cancellation instead of treating it as a hard failure:
import "github.com/containerd/errdefs"
if errdefs.IsCanceled(err) { /* user declined; not fatal */ }

Try / catch

out, output, err := runPrune(ctx, cli, opts)
if err != nil {
    var cancelled interface{ Cancelled() }
    if errors.As(err, &cancelled) { /* user declined the prune prompt; handle gracefully */ return nil }
    return err
}

Prevention

When it happens

Trigger: Running `docker builder prune` (without -f) and typing 'n'/no at the 'WARNING! ... Are you sure you want to continue?' prompt; or piping 'n' into the prompt's stdin.

Common situations: Automated/interactive scripts that forget -f and get the prompt; CI that answers 'no'; users aborting after reading the warning.

Related errors


AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07). Data as JSON: /api/errors/b4835649dc69a15d. Report an issue: GitHub.

Appendix: source

Thrown at cli/command/builder/prune.go:84

const (
	normalWarning   = `WARNING! This will remove all dangling build cache. Are you sure you want to continue?`
	allCacheWarning = `WARNING! This will remove all build cache. Are you sure you want to continue?`
)

func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint64, output string, err error) {
	pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())

	warning := normalWarning
	if options.all {
		warning = allCacheWarning
	}
	if !options.force {
		r, err := prompt.Confirm(ctx, dockerCli.In(), dockerCli.Out(), warning)
		if err != nil {
			return 0, "", err
		}
		if !r {
			return 0, "", cancelledErr{errors.New("builder prune has been cancelled")}
		}
	}

	resp, err := dockerCli.Client().BuildCachePrune(ctx, client.BuildCachePruneOptions{
		All:           options.all,
		ReservedSpace: options.reservedSpace.Value(),
		Filters:       pruneFilters,
	})
	if err != nil {
		return 0, "", err
	}
	report := resp.Report
	if len(report.CachesDeleted) > 0 {
		var sb strings.Builder
		sb.WriteString("Deleted build cache objects:\n")
		for _, id := range report.CachesDeleted {
			sb.WriteString(id)
			sb.WriteByte('\n')

View on GitHub (pinned to 4f84911bfe)