{"record":{"id":"31320d7f383955ce","repo":"dagger/dagger","slug":"unknown-command-or-file-q-for-q-s","errorCode":null,"errorMessage":"unknown command or file %q for %q%s","messagePattern":"unknown command or file %q for %q(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/dagger/main.go","lineNumber":333,"sourceCode":"\t\tt.Capture(cmd.Context(), \"cli_command\", map[string]string{\n\t\t\t\"name\": commandName(cmd),\n\t\t})\n\n\t\treturn nil\n\t},\n\tRunE: runRoot,\n}\n\nfunc runRoot(cmd *cobra.Command, args []string) error {\n\t// Historically, the root command fell back to the hidden shell command:\n\t// `dagger`, `dagger -c ...`, and `dagger file.dsh` all executed shell.\n\t// Bare `dagger` now prints regular CLI usage, but explicit shell-style root\n\t// invocations still take the old fallback below.\n\tif len(args) == 0 && !hasChangedRootShellFlag(cmd) {\n\t\treturn cmd.Usage()\n\t}\n\tif len(args) > 0 && !isFile(args[0]) {\n\t\treturn fmt.Errorf(\"unknown command or file %q for %q%s\", args[0], cmd.CommandPath(), findSuggestions(cmd, args[0]))\n\t}\n\tcmd.SetArgs(append([]string{\"shell\"}, args...))\n\treturn cmd.Execute()\n}\n\nfunc hasChangedRootShellFlag(cmd *cobra.Command) bool {\n\t// Cobra stores parsed persistent and local flags together in cmd.Flags().\n\t// Only root-local flags signal an explicit shell-style invocation; global\n\t// flags like `--debug` should not keep the old shell fallback.\n\tchanged := false\n\tpersistent := cmd.PersistentFlags()\n\tcmd.Flags().Visit(func(flag *pflag.Flag) {\n\t\tif persistent.Lookup(flag.Name) == nil {\n\t\t\tchanged = true\n\t\t}\n\t})\n\treturn changed\n}","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/internal/cmd/dagger/main.go#L315-L351","documentation":"Raised by runRoot when the first positional argument of a bare `dagger` invocation is neither a known subcommand nor an existing file path. The root command only auto-forwards to `dagger shell` when args[0] is a file (via isFile); otherwise it reports the unknown argument with cobra suggestions.","triggerScenarios":"Run `dagger <arg>` where `<arg>` is not a registered subcommand and isFile(arg) is false at main.go:333, e.g. a typo or a path to a file that does not exist.","commonSituations":"Typo in a subcommand name (`dagger sheel`); passing a filename that was deleted or mis-spelled relative to CWD; running an old command name removed in a newer CLI version.","solutions":["Check spelling of the subcommand; cobra suggestions appended to the error often list near matches.","If intending to open a dagger config/file, verify the path exists relative to the current directory.","Run `dagger --help` to list valid commands for this CLI version."],"exampleFix":"// before\ndagger sheel\n// after\ndagger shell","handlingStrategy":"validation","validationCode":"arg := os.Args[1]\nif !isKnownSubcommand(arg) && !isFile(arg) {\n    return fmt.Errorf(\"%q is not a dagger command or an existing file; see `dagger --help`\", arg)\n}","typeGuard":null,"tryCatchPattern":"if err := runRoot(cmd, args); err != nil { fmt.Fprintln(os.Stderr, err); os.Exit(1) }","preventionTips":["Tab-complete dagger subcommands instead of typing them.","Run dagger from the directory containing the target file, or use absolute paths.","After upgrading dagger, re-check command names against `dagger --help`."],"tags":["cli","argument-parsing","cobra"],"backgroundTag":"unknown-command","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}