{"record":{"id":"6af01182d71d05c9","repo":"golang/go","slug":"unknown-command","errorCode":null,"errorMessage":"unknown command","messagePattern":"unknown command","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/script/engine.go","lineNumber":550,"sourceCode":"\t\t\t\treturn false, fmt.Errorf(\"condition %q requires a suffix\", cond.tag)\n\t\t\t}\n\t\t}\n\t\tactive, err := impl.Eval(s, suffix)\n\n\t\tif err != nil {\n\t\t\treturn false, fmt.Errorf(\"evaluating condition %q: %w\", cond.tag, err)\n\t\t}\n\t\tif active != cond.want {\n\t\t\treturn false, nil\n\t\t}\n\t}\n\n\treturn true, nil\n}\n\nfunc (e *Engine) runCommand(s *State, cmd *command, impl Cmd) error {\n\tif impl == nil {\n\t\treturn cmdError(cmd, errors.New(\"unknown command\"))\n\t}\n\n\tasync := impl.Usage().Async\n\tif cmd.background && !async {\n\t\treturn cmdError(cmd, errors.New(\"command cannot be run in background\"))\n\t}\n\n\twait, runErr := impl.Run(s, cmd.args...)\n\tif wait == nil {\n\t\tif async && runErr == nil {\n\t\t\treturn cmdError(cmd, errors.New(\"internal error: async command returned a nil WaitFunc\"))\n\t\t}\n\t\treturn checkStatus(cmd, runErr)\n\t}\n\tif runErr != nil {\n\t\treturn cmdError(cmd, errors.New(\"internal error: command returned both an error and a WaitFunc\"))\n\t}\n","sourceCodeStart":532,"sourceCodeEnd":568,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/script/engine.go#L532-L568","documentation":"Returned by Engine.runCommand when the parsed command name has no entry in the Engine's Cmds map (impl == nil). The engine dispatches command names to registered Cmd implementations; an unregistered name is treated as a script error wrapped via cmdError so it carries the command's source location.","triggerScenarios":"A script line invoking a command name that was not registered in Engine.Cmds — a typo, a removed/renamed command, or a custom engine that registered only a subset. Distinct from a command returning an error at runtime: this fires before Run is called.","commonSituations":"Typo in a script-test command (e.g. `mvv` instead of `mv`), using a command that only exists in a different engine configuration, or forgetting to include script.DefaultCmds() when building a custom Cmds map.","solutions":["Check the command spelling against the registered Cmds (use the Help command to list them).","Ensure your Engine was built with the full command set, e.g. include script.DefaultCmds().","Register the custom command you intended to call."],"exampleFix":"// before\neng := &script.Engine{Cmds: map[string]script.Cmd{}} // empty\n// script: 'cp a b' -> unknown command\n\n// after\neng := &script.Engine{Cmds: script.DefaultCmds()}","handlingStrategy":"validation","validationCode":"// Confirm a command name is registered before running the script.\nfunc knownCommand(name string, cmds map[string]script.Cmd) bool {\n    _, ok := cmds[name]\n    return ok\n}","typeGuard":"func isUnknownCommand(err error) bool {\n    var ce *script.CommandError\n    return errors.As(err, &ce) && ce.Err != nil && ce.Err.Error() == \"unknown command\"\n}","tryCatchPattern":"// Surface registered command names in test output for easy debugging.","preventionTips":["Build the Engine with the full command set (script.DefaultCmds()).","Run `help` in a smoke-test script to list available commands.","Watch for typos when writing script tests."],"tags":["script","engine","test-framework","command-dispatch"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}