{"record":{"id":"f983622aa89cde50","repo":"pbakaus/impeccable","slug":"generate-image-background-must-be-transparent-opaque-or-auto","errorCode":null,"errorMessage":"generate-image: --background must be transparent, opaque, or auto.\n","messagePattern":"generate-image: --background must be transparent, opaque, or auto\\.\n","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/context/src/generate_image.rs","lineNumber":255,"sourceCode":"}\n\nfn parse_size(s: &str) -> (usize, usize) {\n    if let Some((a, b)) = s.split_once('x') {\n        if !a.is_empty() && !b.is_empty() && a.chars().all(|c| c.is_ascii_digit()) && b.chars().all(|c| c.is_ascii_digit()) {\n            return (a.parse().unwrap_or(1536), b.parse().unwrap_or(1024));\n        }\n    }\n    (1536, 1024)\n}\n\npub fn run(args: &[String], io: &mut Io) -> i32 {\n    run_with_api_base(args, io, \"https://api.openai.com/v1\")\n}\n\nfn run_with_api_base(args: &[String], io: &mut Io, api_base: &str) -> i32 {\n    let background = arg(args, \"background\");\n    if args.iter().any(|a| a == \"--background\") && !matches!(background.as_deref(), Some(\"transparent\" | \"opaque\" | \"auto\")) {\n        io.err(\"generate-image: --background must be transparent, opaque, or auto.\\n\");\n        return 1;\n    }\n    let transparent = background.as_deref() == Some(\"transparent\");\n    if background.is_some() && arg(args, \"out\").is_some_and(|out| !out.to_ascii_lowercase().ends_with(\".png\")) {\n        io.err(\"generate-image: --background requires a .png --out path.\\n\");\n        return 1;\n    }\n    let cwd = io.cwd.to_string_lossy().into_owned();\n    let env: Env = io.env.clone();\n    let abs = |p: &str| jsp::resolve(&cwd, &[p]);\n    let read_prompt_file = |io: &mut Io, pf: &str| -> Result<String, i32> {\n        match std::fs::read(abs(pf)) {\n            Ok(b) => Ok(String::from_utf8_lossy(&b).into_owned()),\n            Err(e) => {\n                io.err(&format!(\"Error: {}\\n\", node_read_error(pf, &e)));\n                Err(1)\n            }\n        }","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/pbakaus/impeccable/blob/f2c7051853848826aac2f4646581d62a732155ad/crates/context/src/generate_image.rs#L237-L273","documentation":"generate-image checks that any `--background` argument carries one of the three supported values (`transparent`, `opaque`, `auto`) before calling the OpenAI image API. This early guard exits with status 1 rather than sending an invalid parameter upstream.","triggerScenarios":"Invoking `generate-image ... --background <bad-value>` (e.g. `--background yes`, `--background None`), or passing `--background` with an empty/whitespace value so the value fails the `matches!(\"transparent\" | \"opaque\" | \"auto\")` check.","commonSituations":"Scripting the CLI with a variable that is empty or holds an unexpected value, migrating from another generator whose background flag took different values, or typos like `trasparent`.","solutions":["Use one of the three accepted values: `--background transparent`, `--background opaque`, or `--background auto`.","Remove --background if you don't need background control.","In scripts, validate the shell variable before interpolation (e.g. only pass the flag when the value is in the allowed set)."],"exampleFix":"// before\ngenerate-image --prompt \"logo\" --background alpha --out logo.png\n// after\ngenerate-image --prompt \"logo\" --background transparent --out logo.png","handlingStrategy":"validation","validationCode":"const args = process.argv.slice(2);\nconst i = args.indexOf('--background');\nif (i !== -1 && !['transparent', 'opaque', 'auto'].includes(args[i + 1])) {\n  throw new Error(`--background must be transparent, opaque, or auto (got: ${args[i + 1]})`);\n}","typeGuard":"const isBackgroundValue = (v) => v === 'transparent' || v === 'opaque' || v === 'auto';","tryCatchPattern":null,"preventionTips":["Use a whitelist type guard on background values before spawning the CLI.","Watch for empty variables in shell interpolation (\"--background $BG\" with BG unset).","Quote and normalize flag values to lowercase before passing them."],"tags":["cli","validation","openai"],"backgroundTag":"invalid-flag-value","analyzedSha":"f2c7051853848826aac2f4646581d62a732155ad","analyzedAt":"2026-09-16T20:43:47.549Z","contentChangedAt":"2026-09-16T20:43:47.549Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}