{"record":{"id":"6872f6918ae97174","repo":"jesseduffield/lazydocker","slug":"command-output","errorCode":null,"errorMessage":"{command output}","messagePattern":"\\{command output\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/os.go","lineNumber":289,"sourceCode":"\t\t\treturn false, nil\n\t\t}\n\t\treturn false, err\n\t}\n\treturn true, nil\n}\n\n// RunPreparedCommand takes a pointer to an exec.Cmd and runs it\n// this is useful if you need to give your command some environment variables\n// before running it\nfunc (c *OSCommand) RunPreparedCommand(cmd *exec.Cmd) error {\n\tout, err := cmd.CombinedOutput()\n\toutString := string(out)\n\tc.Log.Info(outString)\n\tif err != nil {\n\t\tif len(outString) == 0 {\n\t\t\treturn err\n\t\t}\n\t\treturn errors.New(outString)\n\t}\n\treturn nil\n}\n\n// GetLazydockerPath returns the path of the currently executed file\nfunc (c *OSCommand) GetLazydockerPath() string {\n\tex, err := os.Executable() // get the executable path for docker to use\n\tif err != nil {\n\t\tex = os.Args[0] // fallback to the first call argument if needed\n\t}\n\treturn filepath.ToSlash(ex)\n}\n\n// RunCustomCommand returns the pointer to a custom command\nfunc (c *OSCommand) RunCustomCommand(command string) *exec.Cmd {\n\treturn c.NewCmd(c.Platform.shell, c.Platform.shellArg, command)\n}\n","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/jesseduffield/lazydocker/blob/7e7aadc2071d58031bf2daafca1fbd4093efc23f/pkg/commands/os.go#L271-L307","documentation":"RunPreparedCommand runs an exec.Cmd via CombinedOutput() and, if it fails, returns the combined stdout+stderr as the error text (falling back to the raw err only when output is empty). The '{command output}' placeholder is literal in the source — the real message is whatever the command printed. It exists so failures from prepared commands (with custom env) surface the subprocess's own diagnostics.","triggerScenarios":"Any code path that builds an exec.Cmd (e.g. with extra env vars) and passes it to RunPreparedCommand where the command exits non-zero: failed docker CLI invocations, editor exits, custom commands from config.","commonSituations":"Custom commands defined in lazydocker config that fail; docker CLI auth/permission failures surfacing through prepared commands; attached commands whose output interleaves stdout and stderr making the error message noisy.","solutions":["Read the returned message — it is the command's own stdout/stderr and contains the actual failure reason.","Run the same command manually in a shell with the same environment to reproduce.","If output is empty and you get a bare 'exit status N', inspect the exit code and check whether the binary exists at all (exec errors).","For custom user commands in config, test the command string standalone before wiring it into lazydocker."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := osCommand.RunPreparedCommand(cmd); err != nil {\n    // message == combined stdout+stderr of the command\n    fmt.Fprintf(os.Stderr, \"command failed:\\n%s\\n\", err.Error())\n    return err\n}","preventionTips":["Test custom commands standalone before wiring them into config.","Pass commands that produce useful diagnostics — output becomes the error text.","Remember empty-output failures surface as bare 'exit status N'; check exit codes separately if you need precision."],"tags":["subprocess","exec","stderr","wrapper","custom-commands"],"backgroundTag":null,"analyzedSha":"7e7aadc2071d58031bf2daafca1fbd4093efc23f","analyzedAt":"2026-08-15T09:51:48.093Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}