{"record":{"id":"2d17176ce229f7c5","repo":"tonhowtf/omniget","slug":"cor-inv-lida-raw","errorCode":null,"errorMessage":"cor inválida: {raw}","messagePattern":"cor inválida: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/img_bg.rs","lineNumber":146,"sourceCode":"\n#[derive(Debug, Clone, Serialize)]\npub struct BgResult {\n    pub model: String,\n    pub items: Vec<BgItem>,\n    pub done: usize,\n    pub failed: usize,\n}\n\n// ── Peças puras (testadas sem modelo nem runtime) ──────────────────────\n\n/// `#RGB`, `#RRGGBB` ou `#RRGGBBAA`. Vazio devolve `None` (= transparente).\npub fn parse_hex_color(raw: &str) -> anyhow::Result<Option<Rgba<u8>>> {\n    let s = raw.trim().trim_start_matches('#');\n    if s.is_empty() {\n        return Ok(None);\n    }\n    let byte = |i: usize| -> anyhow::Result<u8> {\n        u8::from_str_radix(&s[i..i + 2], 16).map_err(|_| anyhow!(\"cor inválida: {raw}\"))\n    };\n    let px = match s.len() {\n        3 => {\n            let mut v = [0u8; 3];\n            for (i, c) in s.chars().enumerate() {\n                let d = c\n                    .to_digit(16)\n                    .ok_or_else(|| anyhow!(\"cor inválida: {raw}\"))? as u8;\n                v[i] = d * 17;\n            }\n            Rgba([v[0], v[1], v[2], 255])\n        }\n        6 => Rgba([byte(0)?, byte(2)?, byte(4)?, 255]),\n        8 => Rgba([byte(0)?, byte(2)?, byte(4)?, byte(6)?]),\n        _ => return Err(anyhow!(\"cor inválida: {raw}\")),\n    };\n    Ok(Some(px))\n}","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/img_bg.rs#L128-L164","documentation":"Raised by the `byte` closure inside `parse_hex_color` when a 2-character hex slice cannot be parsed as a base-16 u8. It fires while decoding 6- or 8-digit hex color components in the img_bg tool's background color option.","triggerScenarios":"Calling `parse_hex_color` with a string whose length is 6 or 8 (after trimming '#' and whitespace) but containing non-hex characters, e.g. \"#GGHHII\" or \"12345z8\".","commonSituations":"Typo in a config value for the background color; pasted color with stray letters or the '0x' prefix; lowercase/uppercase confusion is fine but accidental characters like 'O' instead of '0' are not.","solutions":["Provide a valid hex color string: exactly 3, 6, or 8 hex digits ([0-9a-fA-F]) after an optional '#'.","Sanitize the value at the UI/config layer with a regex like ^#?(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$ before calling.","Use a color picker component that emits well-formed hex values instead of free text."],"exampleFix":"// before\nlet bg = parse_hex_color(\"#GG2255\")?; // panics into: cor inválida: #GG2255\n// after\nlet raw = \"#GG2255\";\nlet valid = regex::Regex::new(r\"^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$\").unwrap();\nif !valid.is_match(raw) { eprintln!(\"use um hex válido, ex: #FF00AA\"); return Ok(()); }\nlet bg = parse_hex_color(raw)?;","handlingStrategy":"validation","validationCode":"fn is_valid_hex6(s: &str) -> bool {\n    let s = s.trim().trim_start_matches('#');\n    s.len() == 6 && s.chars().all(|c| c.is_ascii_hexdigit())\n}","typeGuard":"fn is_hex_color(raw: &str) -> bool {\n    let s = raw.trim().trim_start_matches('#');\n    matches!(s.len(), 3 | 6 | 8) && s.chars().all(|c| c.is_ascii_hexdigit())\n}","tryCatchPattern":"match parse_hex_color(raw) {\n    Ok(Some(color)) => apply(color),\n    Ok(None) => {}, // empty means \"keep default\"\n    Err(e) => eprintln!(\"use hex como #RRGGBB: {e}\"),\n}","preventionTips":["Use a color picker widget instead of free-text input","Validate with a hex regex at config load time","Normalize input (trim, strip #) before validating"],"tags":["validation","hex-color","parsing","rust"],"backgroundTag":"invalid-argument-format","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}