{"record":{"id":"a4bcaf666f5c18d8","repo":"wagoodman/dive","slug":"failed-to-set-ui-w","errorCode":null,"errorMessage":"failed to set UI: %w","messagePattern":"failed to set UI: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/dive/cli/internal/command/build.go","lineNumber":28,"sourceCode":")\n\ntype buildOptions struct {\n\toptions.Application `yaml:\",inline\" mapstructure:\",squash\"`\n\n\t// reserved for future use of build-only flags\n}\n\nfunc Build(app clio.Application) *cobra.Command {\n\topts := &buildOptions{\n\t\tApplication: options.DefaultApplication(),\n\t}\n\treturn app.SetupCommand(&cobra.Command{\n\t\tUse:                \"build [any valid `docker build` arguments]\",\n\t\tShort:              \"Builds and analyzes a docker image from a Dockerfile (this is a thin wrapper for the `docker build` command).\",\n\t\tDisableFlagParsing: true,\n\t\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\t\tif err := setUI(app, opts.Application); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to set UI: %w\", err)\n\t\t\t}\n\n\t\t\tresolver, err := dive.GetImageResolver(opts.Analysis.Source)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"cannot determine image provider for build: %w\", err)\n\t\t\t}\n\n\t\t\tctx := cmd.Context()\n\n\t\t\timg, err := adapter.ImageResolver(resolver).Build(ctx, args)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"cannot build image: %w\", err)\n\t\t\t}\n\n\t\t\treturn run(cmd.Context(), opts.Application, img, resolver)\n\t\t},\n\t}, opts)\n}","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/wagoodman/dive/blob/d6c691947f8fda635c952a17ee3b7555379d58f0/cmd/dive/cli/internal/command/build.go#L10-L46","documentation":"Returned at the start of `dive build` when setUI fails to install the UI implementation into the application state (state.UI.Replace(ux)). setUI constructs the v1 gocui UI bound to os.Stdout and replaces the current UI; failure means the UI could not be created or swapped — typically an invalid terminal (no TTY), unsupported terminal size, or a UI driver initialization error.","triggerScenarios":"Running `dive build .` in an environment without a TTY (piped stdout in CI, docker exec without -t, some IDE consoles), or with a terminal that gocui cannot initialize.","commonSituations":"Running dive build inside CI without a pseudo-terminal; piping output (dive build . | cat); minimal shells where TERM is unset or invalid.","solutions":["Run dive build in a real terminal or allocate a TTY (docker exec -it, script -qc 'dive build .')","Set a valid TERM environment variable (e.g. export TERM=xterm)","For non-interactive contexts use the CI/export modes instead of the interactive UI","Check the wrapped error for the specific gocui failure (e.g. terminal size 0x0)"],"exampleFix":"# before (no TTY in CI)\ndive build . | tee build.log\n\n# after (non-interactive: use CI mode)\ndive build . --ci < build-context || true\ndive <built-image> --ci","handlingStrategy":"validation","validationCode":"# fail fast in scripts when no TTY is present\n[ -t 1 ] || { echo 'dive build needs a TTY; use --ci/--json instead'; exit 2; }\ndive build .","typeGuard":null,"tryCatchPattern":"if err := setUI(app, opts.Application); err != nil {\n    if strings.Contains(err.Error(), \"failed to set UI\") || !isatty.IsTerminal(os.Stdout.Fd()) {\n        // no usable terminal: rerun in CI mode instead of the TUI\n    }\n    return err\n}","preventionTips":["Gate interactive dive usage on [ -t 1 ] in automation scripts","Use --ci or --json for any non-interactive context","Ensure TERM is set in minimal container shells"],"tags":["ui","tty","terminal","build","gocui"],"backgroundTag":null,"analyzedSha":"d6c691947f8fda635c952a17ee3b7555379d58f0","analyzedAt":"2026-08-15T09:42:35.293Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}