{"record":{"id":"ff8a8ed83793743a","repo":"Hmbown/CodeWhale","slug":"invalid-key-value-expected-min-max","errorCode":null,"errorMessage":"Invalid {key} '{value}': expected {min}-{max}","messagePattern":"Invalid (.+?) '(.+?)': expected (.+?)-(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/settings.rs","lineNumber":2586,"sourceCode":"fn default_true() -> bool {\n    true\n}\n\nfn parse_usize_setting(key: &str, value: &str) -> Result<usize> {\n    value.trim().parse::<usize>().map_err(|_| {\n        anyhow::anyhow!(\n            \"Failed to update setting: invalid {key} '{value}'. Expected 0 or a positive integer.\"\n        )\n    })\n}\n\nfn parse_u16_range(key: &str, value: &str, min: u16, max: u16) -> Result<u16> {\n    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}","sourceCodeStart":2568,"sourceCodeEnd":2604,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/settings.rs#L2568-L2604","documentation":"Thrown by parse_u16_range when a u16-bounded TUI setting receives a value that either fails u16 parsing or falls outside the [min, max] window the setting declares. The parse failure and the range failure produce the identical message, so 'expected {min}-{max}' also covers non-numeric input. Bounds come from the caller, so the message always states the real window.","triggerScenarios":"Calling ':set <u16-key> <value>' where the value is not an in-range u16: '70000' (overflows u16), '-1' (u16 rejects signs), 'abc', or an in-type but out-of-window value like '0' when the key's declared min is 1.","commonSituations":"Port numbers above 65535, counts set to 0 when the schema demands at least 1, decimals like '2.5', thousands separators or trailing units ('8080,' or '10s'), and pasted values with stray whitespace or symbols.","solutions":["Re-issue the set with a plain integer inside the advertised min-max window (no units, no separators).","If you intended 0, check whether this key routes through the sibling '0 or a positive integer' parser instead.","Strip whitespace and units before sending; the parser trims outer whitespace but nothing else.","For wrappers, parse and range-check the value client-side before issuing the set."],"exampleFix":"# before\n:set history_limit 99999\n\n# after (window advertised by the error, e.g. 1-10000)\n:set history_limit 10000","handlingStrategy":"validation","validationCode":"fn in_u16_window(value: &str, min: u16, max: u16) -> bool {\n    matches!(value.trim().parse::<u16>(), Ok(v) if (min..=max).contains(&v))\n}","typeGuard":null,"tryCatchPattern":"match parse_u16_range(key, value, min, max) {\n    Err(err) if err.to_string().starts_with(\"Invalid\") => retry_with_corrected_value(),\n    other => other?,\n}","preventionTips":["Range-check numeric config in the wrapper before sending it to the TUI.","Remember u16 rejects signs and values above 65535 at parse time.","Keep the advertised window in the error copy in sync with the schema."],"tags":["settings","u16","range","validation","tui","rust"],"backgroundTag":"numeric-config-out-of-range","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}