{"record":{"id":"774a8351ca64bc83","repo":"hashicorp/nomad","slug":"failed-to-generate-logging-ui","errorCode":null,"errorMessage":"failed to generate logging UI","messagePattern":"failed to generate logging UI","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/ui/log_ui.go","lineNumber":70,"sourceCode":"\t\tlogUI.warnColor = coloredUI.WarnColor\n\t\tlogUI.underlyingUI = coloredUI.Ui\n\n\t\tif basicUI, ok := coloredUI.Ui.(*cli.BasicUi); ok {\n\t\t\tlogUI.reader = basicUI.Reader\n\t\t\tlogUI.writer = basicUI.Writer\n\t\t\tlogUI.errorWriter = basicUI.ErrorWriter\n\t\t\tfound = true\n\t\t}\n\t} else if basicUI, ok := ui.(*cli.BasicUi); ok && !found {\n\t\tlogUI.reader = basicUI.Reader\n\t\tlogUI.writer = basicUI.Writer\n\t\tlogUI.errorWriter = basicUI.ErrorWriter\n\t\tlogUI.underlyingUI = basicUI\n\t\tfound = true\n\t}\n\n\tif !found {\n\t\treturn nil, errors.New(\"failed to generate logging UI\")\n\t}\n\n\treturn &logUI, nil\n}\n\n// Ask implements the Ask function of the cli.Ui interface.\nfunc (l *LogUI) Ask(query string) (string, error) {\n\treturn l.underlyingUI.Ask(l.colorize(query, l.outputColor))\n}\n\n// AskSecret implements the AskSecret function of the cli.Ui interface.\nfunc (l *LogUI) AskSecret(query string) (string, error) {\n\treturn l.underlyingUI.AskSecret(l.colorize(query, l.outputColor))\n}\n\n// Output implements the Output function of the cli.Ui interface.\nfunc (l *LogUI) Output(message string) {\n\t_, _ = fmt.Fprint(l.writer, l.colorize(message, l.outputColor))","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/ui/log_ui.go#L52-L88","documentation":"NewLogUI builds the logging UI (mitchellh/cli-based) used by `nomad ui` logging-related commands. It succeeds if it can wire either a colorized or basic UI from the provided options; if none of the known UI flavors could be constructed (the `found` flag stays false), it returns this error.","triggerScenarios":"Calling NewLogUI with a configuration that matches neither the colorized nor the basic UI path — e.g. nil/invalid CLI options or UI configuration leaving no supported underlying UI available.","commonSituations":"Programmatic callers constructing the UI with incomplete cli.Ui options; embedding nomad command code with non-standard writers; misconfigured nomad UI setup.","solutions":["Pass a valid, non-nil configuration: ensure the input/output/error writers (or a supported underlying cli.Ui) are provided so one of the code paths sets found=true.","Use a plain basic UI (cli.NewBasicUi) as fallback input so at least the basic path succeeds.","Update Nomad if hitting this with options that should be supported; check for regressions in ui/log_ui.go."],"exampleFix":"// before\nlogUI, err := NewLogUI(nil) // no usable UI options\n// after\nbasicUI := cli.NewBasicUi(cli.BasicUiOpts{Writer: os.Stdout, ErrorWriter: os.Stderr})\nlogUI, err := NewLogUI(basicUI)","handlingStrategy":"validation","validationCode":"if uiOpts == nil || (uiOpts.Writer == nil && uiOpts.ErrorWriter == nil) {\n    return errors.New(\"LogUI requires valid writer options\")\n}","typeGuard":"func canBuildLogUI(o *LogUIOptions) bool { return o != nil && (o.Writer != nil || o.UnderlyingUI != nil) }","tryCatchPattern":"logUI, err := NewLogUI(opts)\nif err != nil && strings.Contains(err.Error(), \"failed to generate logging UI\") {\n    logUI = cli.NewBasicUi(cli.BasicUiOpts{Writer: os.Stdout, ErrorWriter: os.Stderr})\n}","preventionTips":["Always pass a supported underlying cli.Ui or valid writers to NewLogUI.","Fall back to cli.NewBasicUi when custom UI construction fails.","Cover NewLogUI with unit tests for each supported option combination."],"tags":["ui","logging","cli","initialization"],"backgroundTag":"ui-initialization-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}