{"record":{"id":"ce690ffc93a4b385","repo":"docker/cli","slug":"network-prune-has-been-cancelled","errorCode":null,"errorMessage":"network prune has been cancelled","messagePattern":"network prune has been cancelled","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cli/command/network/prune.go","lineNumber":71,"sourceCode":"\tflags.BoolVarP(&options.force, \"force\", \"f\", false, \"Do not prompt for confirmation\")\n\tflags.Var(&options.filter, \"filter\", `Provide filter values (e.g. \"until=<timestamp>\")`)\n\n\treturn cmd\n}\n\nconst warning = `WARNING! This will remove all custom networks not used by at least one container.\nAre you sure you want to continue?`\n\nfunc runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) (output string, _ error) {\n\tpruneFilters := command.PruneFilters(dockerCli, options.filter.Value())\n\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 \"\", err\n\t\t}\n\t\tif !r {\n\t\t\treturn \"\", cancelledErr{errors.New(\"network prune has been cancelled\")}\n\t\t}\n\t}\n\n\tres, err := dockerCli.Client().NetworkPrune(ctx, client.NetworkPruneOptions{\n\t\tFilters: pruneFilters,\n\t})\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tvar out strings.Builder\n\tif len(res.Report.NetworksDeleted) > 0 {\n\t\tout.WriteString(\"Deleted Networks:\\n\")\n\t\tfor _, id := range res.Report.NetworksDeleted {\n\t\t\tout.WriteString(id + \"\\n\")\n\t\t}\n\t}\n","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/network/prune.go#L53-L89","documentation":"Returned wrapped in a cancelledErr (which implements a Cancelled() marker method) from runPrune when the user answers 'no' to the interactive confirmation prompt and --force was not passed. This is not a real failure; it signals an intentional user cancellation of the destructive prune operation.","triggerScenarios":"Running 'docker network prune' without -f/--force and responding 'n' (or anything non-affirmative) at the 'Are you sure you want to continue?' prompt (lines 65-72).","commonSituations":"Scripted or interactive runs where the operator declines to delete unused networks; piping 'n' into the prompt; automation that forgot the --force flag.","solutions":["If you intend to prune, pass --force (-f) to skip the confirmation prompt.","If cancellation was intentional, treat the non-zero exit as expected and ignore it in scripts.","Check the Cancelled() marker on the error to distinguish cancellation from real failures."],"exampleFix":"# before\ndocker network prune   # then type n\n# after\ndocker network prune --force","handlingStrategy":"validation","validationCode":"// In scripts, pass --force to avoid the prompt, or detect cancellation by marker\nif !options.force {\n    // confirm interactively yourself, then run with --force if confirmed\n}","typeGuard":null,"tryCatchPattern":"// Distinguish a user cancellation from a real error\nerr := runPrune(ctx, cli, opts)\nif err != nil {\n    var c cancelledErr\n    if errors.As(err, &c) {\n        // user declined; not a failure\n        return nil\n    }\n    return err\n}","preventionTips":["Use --force (-f) in automation to skip the confirmation entirely.","Detect the Cancelled() marker interface to treat cancellation as a non-error.","Do not pipe arbitrary input into the confirmation prompt."],"tags":["network","prune","docker","go","cli","cancellation"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}