{"id":"aa864e7a51539483","repo":"docker/cli","slug":"image-prune-has-been-cancelled","errorCode":null,"errorMessage":"image prune has been cancelled","messagePattern":"image prune has been cancelled","errorType":"exception","errorClass":"cancelledErr","httpStatus":null,"severity":"info","filePath":"cli/command/image/prune.go","lineNumber":86,"sourceCode":"\tdanglingWarning = `WARNING! This will remove all dangling images.\nAre 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\tpruneFilters.Add(\"dangling\", strconv.FormatBool(!options.all))\n\n\twarning := danglingWarning\n\tif options.all {\n\t\twarning = allImageWarning\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(\"image prune has been cancelled\")}\n\t\t}\n\t}\n\n\tres, err := dockerCli.Client().ImagePrune(ctx, client.ImagePruneOptions{\n\t\tFilters: pruneFilters,\n\t})\n\tif err != nil {\n\t\treturn 0, \"\", err\n\t}\n\n\tvar sb strings.Builder\n\tif len(res.Report.ImagesDeleted) > 0 {\n\t\tsb.WriteString(\"Deleted Images:\\n\")\n\t\tfor _, st := range res.Report.ImagesDeleted {\n\t\t\tif st.Untagged != \"\" {\n\t\t\t\tsb.WriteString(\"untagged: \")\n\t\t\t\tsb.WriteString(st.Untagged)\n\t\t\t\tsb.WriteByte('\\n')","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/image/prune.go#L68-L104","documentation":"docker image prune asks for interactive confirmation unless --force/-f is given. In runPrune (cli/command/image/prune.go:80-87), prompt.Confirm shows a warning (dangling-only or all-images) and if the user answers no, the command returns cancelledErr wrapping this message. It signals a deliberate user abort, not a failure of the prune API; the cancelledErr type implements Cancelled() so callers can treat it as a non-fatal cancellation.","triggerScenarios":"Running `docker image prune` (optionally with -a) without --force and answering 'n' (or anything other than yes) at the 'Are you sure you want to continue? [y/N]' prompt, or the prompt being aborted (e.g. Ctrl-C/EOF handled as decline).","commonSituations":"Interactive use where the operator declines after reading the warning; automation/CI running prune without -f on a non-interactive stdin so the confirmation defaults to no; scripts that pipe empty input into docker image prune.","solutions":["If you intended to prune, re-run and answer 'y' at the prompt","In scripts/CI, pass --force (-f) to skip the confirmation: docker image prune -f","Treat this error as an expected cancellation (it satisfies a Cancelled() interface), not a failure"],"exampleFix":"# before (CI hangs or cancels)\ndocker image prune -a\n# after\ndocker image prune -a --force","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker-cli","image-prune","user-cancelled","confirmation-prompt"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}