{"id":"b4835649dc69a15d","repo":"docker/cli","slug":"builder-prune-has-been-cancelled","errorCode":null,"errorMessage":"builder prune has been cancelled","messagePattern":"builder prune has been cancelled","errorType":"exception","errorClass":"cancelledErr","httpStatus":null,"severity":"info","filePath":"cli/command/builder/prune.go","lineNumber":84,"sourceCode":"const (\n\tnormalWarning   = `WARNING! This will remove all dangling build cache. Are you sure you want to continue?`\n\tallCacheWarning = `WARNING! This will remove all build cache. Are you sure you want to continue?`\n)\n\nfunc runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint64, output string, err error) {\n\tpruneFilters := command.PruneFilters(dockerCli, options.filter.Value())\n\n\twarning := normalWarning\n\tif options.all {\n\t\twarning = allCacheWarning\n\t}\n\tif !options.force {\n\t\tr, err := prompt.Confirm(ctx, dockerCli.In(), dockerCli.Out(), warning)\n\t\tif err != nil {\n\t\t\treturn 0, \"\", err\n\t\t}\n\t\tif !r {\n\t\t\treturn 0, \"\", cancelledErr{errors.New(\"builder prune has been cancelled\")}\n\t\t}\n\t}\n\n\tresp, err := dockerCli.Client().BuildCachePrune(ctx, client.BuildCachePruneOptions{\n\t\tAll:           options.all,\n\t\tReservedSpace: options.reservedSpace.Value(),\n\t\tFilters:       pruneFilters,\n\t})\n\tif err != nil {\n\t\treturn 0, \"\", err\n\t}\n\treport := resp.Report\n\tif len(report.CachesDeleted) > 0 {\n\t\tvar sb strings.Builder\n\t\tsb.WriteString(\"Deleted build cache objects:\\n\")\n\t\tfor _, id := range report.CachesDeleted {\n\t\t\tsb.WriteString(id)\n\t\t\tsb.WriteByte('\\n')","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/builder/prune.go#L66-L102","documentation":"docker builder prune asks for interactive confirmation before deleting build cache unless --force is given. When the user answers 'no' (or the prompt is declined), runPrune returns a cancelledErr wrapping this message, which the CLI maps to a cancelled-operation exit rather than performing any prune. The cancelledErr type implements a Cancelled() marker so upstream code exits without treating it as a hard failure.","triggerScenarios":"Running docker builder prune (or docker buildx prune via this path) without --force and responding 'N'/enter at the 'Are you sure you want to continue?' prompt; also when prompt.Confirm returns false because stdin is closed or non-interactive.","commonSituations":"CI scripts running docker builder prune without -f, where stdin is not a TTY so the confirmation defaults to no; users cancelling after seeing the 'remove all build cache' warning with -a; automation wrappers not passing --force.","solutions":["Pass --force (-f) to skip the confirmation prompt in scripts and CI","If cancellation was intentional, no action needed — nothing was deleted","In automation, check for the cancelled marker/exit code and treat it as a no-op rather than a failure"],"exampleFix":"# before\ndocker builder prune --all\n# after (non-interactive)\ndocker builder prune --all --force","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","builder","prune","user-cancelled","prompt"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}