wagoodman/dive · error

failed to set UI: %w

Error message

failed to set UI: %w

What it means

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.

Source

Thrown at cmd/dive/cli/internal/command/build.go:28

)

type buildOptions struct {
	options.Application `yaml:",inline" mapstructure:",squash"`

	// reserved for future use of build-only flags
}

func Build(app clio.Application) *cobra.Command {
	opts := &buildOptions{
		Application: options.DefaultApplication(),
	}
	return app.SetupCommand(&cobra.Command{
		Use:                "build [any valid `docker build` arguments]",
		Short:              "Builds and analyzes a docker image from a Dockerfile (this is a thin wrapper for the `docker build` command).",
		DisableFlagParsing: true,
		RunE: func(cmd *cobra.Command, args []string) error {
			if err := setUI(app, opts.Application); err != nil {
				return fmt.Errorf("failed to set UI: %w", err)
			}

			resolver, err := dive.GetImageResolver(opts.Analysis.Source)
			if err != nil {
				return fmt.Errorf("cannot determine image provider for build: %w", err)
			}

			ctx := cmd.Context()

			img, err := adapter.ImageResolver(resolver).Build(ctx, args)
			if err != nil {
				return fmt.Errorf("cannot build image: %w", err)
			}

			return run(cmd.Context(), opts.Application, img, resolver)
		},
	}, opts)
}

View on GitHub (pinned to d6c691947f)

Solutions

  1. Run dive build in a real terminal or allocate a TTY (docker exec -it, script -qc 'dive build .')
  2. Set a valid TERM environment variable (e.g. export TERM=xterm)
  3. For non-interactive contexts use the CI/export modes instead of the interactive UI
  4. Check the wrapped error for the specific gocui failure (e.g. terminal size 0x0)

Example fix

# before (no TTY in CI)
dive build . | tee build.log

# after (non-interactive: use CI mode)
dive build . --ci < build-context || true
dive <built-image> --ci
Defensive patterns

Strategy: validation

Validate before calling

# fail fast in scripts when no TTY is present
[ -t 1 ] || { echo 'dive build needs a TTY; use --ci/--json instead'; exit 2; }
dive build .

Try / catch

if err := setUI(app, opts.Application); err != nil {
    if strings.Contains(err.Error(), "failed to set UI") || !isatty.IsTerminal(os.Stdout.Fd()) {
        // no usable terminal: rerun in CI mode instead of the TUI
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: Running dive build inside CI without a pseudo-terminal; piping output (dive build . | cat); minimal shells where TERM is unset or invalid.

Related errors


AI-assisted analysis of wagoodman/dive@d6c691947f (2026-08-15). Data as JSON: /api/errors/a4bcaf666f5c18d8. Report an issue: GitHub.