{"record":{"id":"d2ea9c3c53eacb24","repo":"ipfs/kubo","slug":"can-t-combine-all-with-other-matching-options","errorCode":null,"errorMessage":"can't combine --all with other matching options","messagePattern":"can't combine --all with other matching options","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/p2p.go","lineNumber":537,"sourceCode":"\t\t\tlisten, err = ma.NewMultiaddr(listenOpt)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\n\t\tif t {\n\t\t\ttarget, err = ma.NewMultiaddr(targetOpt)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\n\t\tif !(closeAll || p || l || t) {\n\t\t\treturn errors.New(\"no matching options given\")\n\t\t}\n\n\t\tif closeAll && (p || l || t) {\n\t\t\treturn errors.New(\"can't combine --all with other matching options\")\n\t\t}\n\n\t\tmatch := func(listener p2p.Listener) bool {\n\t\t\tif closeAll {\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tif p && proto != listener.Protocol() {\n\t\t\t\treturn false\n\t\t\t}\n\t\t\tif l && !listen.Equal(listener.ListenAddress()) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t\tif t && !target.Equal(listener.TargetAddress()) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn true\n\t\t}\n","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/p2p.go#L519-L555","documentation":"This error comes from the `ipfs p2p close` command pre-run validation in kubo. The `--all` flag closes every active p2p stream/listener, so it is mutually exclusive with the selective filters `--peer`, `--listen`, and `--target`. The command refuses to run when both styles of matching are combined because the intent would be ambiguous.","triggerScenarios":"Running `ipfs p2p close --all` while also passing `--peer <peerID>`, `--listen <address>`, or `--target <address>`; e.g. `ipfs p2p close --all --peer Qm...` or a script that appends `--all` to a filter command.","commonSituations":"Shell scripts that hardcode `--all` as a default flag and then accept user-supplied filters; operators trying to close 'all streams for a given peer' and assuming `--all` scopes the other flags.","solutions":["Remove the `--all` flag if you want to filter by peer/listen/target address.","Remove the `--peer`, `--listen`, and `--target` flags if you truly want to close everything.","Check the output of `ipfs p2p close --help` to confirm which flags are mutually exclusive.","In scripts, branch: build either an `--all` invocation or a filtered invocation, never both."],"exampleFix":"// before\nerr := exec.Command(\"ipfs\", \"p2p\", \"close\", \"--all\", \"--peer\", peerID).Run()\n// after\nerr := exec.Command(\"ipfs\", \"p2p\", \"close\", \"--peer\", peerID).Run()","handlingStrategy":"validation","validationCode":"flags := map[string]bool{\"all\": all, \"peer\": peer != \"\", \"listen\": listen != \"\", \"target\": target != \"\"}\nif flags[\"all\"] && (flags[\"peer\"] || flags[\"listen\"] || flags[\"target\"]) {\n    return errors.New(\"--all cannot be combined with --peer/--listen/--target\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never hardcode --all in scripts that also accept filter flags","Expose either --all OR filters to users, not both","Document flag exclusivity in script usage messages"],"tags":["cli","ipfs","p2p","flag-validation"],"backgroundTag":"mutually-exclusive-flags","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}