{"record":{"id":"21d96d54fdb00a6c","repo":"nikivdev/code","slug":"failed-to-draw-env-setup-ui-err","errorCode":null,"errorMessage":"failed to draw env setup UI: {err}","messagePattern":"failed to draw env setup UI: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/env_setup.rs","lineNumber":242,"sourceCode":"            .unwrap_or_else(|| \"production\".to_string());\n\n        self.result = Some(EnvSetupResult {\n            env_file: self.env_file_path(),\n            environment,\n            selected_keys,\n            apply: self.apply,\n        });\n    }\n}\n\nfn run_app<B: ratatui::backend::Backend>(\n    terminal: &mut Terminal<B>,\n    app: &mut EnvSetupApp,\n) -> Result<Option<EnvSetupResult>> {\n    loop {\n        terminal\n            .draw(|f| draw_ui(f, app))\n            .map_err(|err| anyhow::anyhow!(\"failed to draw env setup UI: {err}\"))?;\n\n        if event::poll(std::time::Duration::from_millis(200))? {\n            if let CEvent::Key(key) = event::read()? {\n                if handle_key(app, key)? {\n                    return Ok(app.result.take());\n                }\n            }\n        }\n    }\n}\n\nfn handle_key(app: &mut EnvSetupApp, key: KeyEvent) -> Result<bool> {\n    match key.code {\n        KeyCode::Char('q') => return Ok(true),\n        KeyCode::Esc => return Ok(step_back(app)),\n        _ => {}\n    }\n","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/env_setup.rs#L224-L260","documentation":"The env setup TUI (`run_app`, invoked by `run_env_setup`) wraps every `terminal.draw(|f| draw_ui(f, app))` call; if the backend draw fails (ratatui/termion/crossterm backend error), it is converted into this anyhow error naming the UI. This typically indicates the terminal backend cannot render — not a problem with the setup logic itself.","triggerScenarios":"`f env setup` starts the interactive TUI and `Terminal::draw` returns an error — e.g. output redirected to a non-terminal/pipe, backend I/O failure, unsupported terminal, or a broken/closed stdout during redraws inside the event loop.","commonSituations":"Running the setup wizard in CI or via `| tee` where stdout is not a TTY; SSH sessions with broken PTY; terminals that reject required escape sequences; very old/unusual TERM settings.","solutions":["Run `f env setup` in a real interactive terminal (no pipes/redirects on stdout)","Check TERM is set to a supported value and the PTY is healthy (reconnect SSH)","Use non-interactive env configuration (flags/config file) if no TTY is available","Read the wrapped backend error in the message for the specific terminal-backend failure"],"exampleFix":"// before\nf env setup | tee setup.log\n// after\nf env setup   # run directly in an interactive terminal; log via `script` if needed","handlingStrategy":"try-catch","validationCode":"if !std::io::stdout().is_terminal() {\n    eprintln!(\"env setup requires an interactive terminal\");\n    std::process::exit(2);\n}","typeGuard":null,"tryCatchPattern":"match run_app(terminal, app) {\n    Err(e) if e.to_string().contains(\"failed to draw env setup UI\") => {\n        eprintln!(\"TUI unavailable ({e}); use non-interactive setup flags instead.\");\n    }\n    other => other?,\n}","preventionTips":["Only launch the setup TUI with a real TTY (no pipes/redirects)","Set a supported TERM value","Provide non-interactive flags for CI/headless environments","Test the wizard over SSH/PTY setups your users actually use"],"tags":["tui","terminal","render"],"backgroundTag":"terminal-render-failure","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}