{"record":{"id":"91b756c6d7bf8720","repo":"Hmbown/CodeWhale","slug":"failed-to-update-setting-invalid-key-value","errorCode":null,"errorMessage":"Failed to update setting: invalid {key} '{value}'. Expected a number from 10 to 100.","messagePattern":"Failed to update setting: invalid (.+?) '(.+?)'\\. Expected a number from 10 to 100\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/settings.rs","lineNumber":2840,"sourceCode":"    let parsed = value\n        .trim()\n        .parse::<u16>()\n        .map_err(|_| anyhow::anyhow!(\"Invalid {key} '{value}': expected {min}-{max}\"))?;\n    if !(min..=max).contains(&parsed) {\n        anyhow::bail!(\"Invalid {key} '{value}': expected {min}-{max}\");\n    }\n    Ok(parsed)\n}\n\nfn parse_percent_setting(key: &str, value: &str) -> Result<f64> {\n    let trimmed = value.trim().trim_end_matches('%').trim();\n    let percent = trimmed.parse::<f64>().map_err(|_| {\n        anyhow::anyhow!(\n            \"Failed to update setting: invalid {key} '{value}'. Expected a number from 10 to 100.\"\n        )\n    })?;\n    if !(10.0..=100.0).contains(&percent) {\n        anyhow::bail!(\n            \"Failed to update setting: invalid {key} '{value}'. Expected a number from 10 to 100.\"\n        );\n    }\n    Ok(percent)\n}\n\nfn normalize_mention_menu_behavior(value: &str) -> Result<String> {\n    match value.trim().to_ascii_lowercase().as_str() {\n        \"fuzzy\" | \"default\" => Ok(\"fuzzy\".to_string()),\n        \"browser\" | \"browse\" | \"file-browser\" | \"file_browser\" => Ok(\"browser\".to_string()),\n        _ => {\n            anyhow::bail!(\n                \"Failed to update setting: invalid mention_menu_behavior '{value}'. Expected: fuzzy, browser.\"\n            )\n        }\n    }\n}\n","sourceCodeStart":2822,"sourceCodeEnd":2858,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/settings.rs#L2822-L2858","documentation":"parse_percent_setting parses a percentage value (optionally with a trailing %) and requires the number to be within 10.0–100.0 inclusive. Non-numeric input and out-of-range values both raise this error with the 10–100 expectation stated. It guards percentage-style settings from invalid bounds.","triggerScenarios":"Setting a percentage setting with non-numeric text (\"abc\", \"half\") or a number below 10 or above 100, e.g. `/setting context_percent 5` or `150%`.","commonSituations":"Setting a percentage too low thinking 0–100 was allowed; typos like \"1O\" (letter O); pasting values with currency or other suffixes.","solutions":["Provide a number between 10 and 100, optionally with a trailing %","Remove non-numeric characters except a decimal point and optional %","If you intended a smaller value, check the setting's minimum is indeed 10"],"exampleFix":"// before\nset context_percent 5\n// after\nset context_percent 10","handlingStrategy":"validation","validationCode":"fn valid_percent(v: &str) -> bool {\n    match v.trim().trim_end_matches('%').trim().parse::<f64>() {\n        Ok(n) => (10.0..=100.0).contains(&n),\n        Err(_) => false,\n    }\n}","typeGuard":null,"tryCatchPattern":"match parse_percent_setting(key, raw) {\n    Ok(p) => /* use p */,\n    Err(e) if e.to_string().contains(\"10 to 100\") => {\n        eprintln!(\"{e}\"); // clamp or prompt the user for 10-100\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Validate the numeric range 10-100 before calling","Allow but strip a trailing '%' if your UI supplies one","Reject non-numeric input at the UI layer with immediate feedback"],"tags":["parsing","validation","numeric-range","settings"],"backgroundTag":"value-out-of-range","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}