{"record":{"id":"4d13b595f0b59367","repo":"ducaale/xh","slug":"is-not-a-supported-encoding-please-refer-to-https-encoding","errorCode":null,"errorMessage":"{} is not a supported encoding, please refer to https://encoding.spec.whatwg.org/#names-and-labels for supported encodings","messagePattern":"(.+?) is not a supported encoding, please refer to https://encoding\\.spec\\.whatwg\\.org/#names-and-labels for supported encodings","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli.rs","lineNumber":1414,"sourceCode":"        &normalized_encoding.replace('_', \"-\"),\n        &normalized_encoding.replace('-', \"_\"),\n    ] {\n        if let Some(encoding) = Encoding::for_label(encoding.as_bytes()) {\n            return Ok(encoding);\n        }\n    }\n\n    {\n        let mut encoding = normalized_encoding.replace(&['-', '_'][..], \"\");\n        if let Some(first_digit_index) = encoding.find(|c: char| c.is_ascii_digit()) {\n            encoding.insert(first_digit_index, '-');\n            if let Some(encoding) = Encoding::for_label(encoding.as_bytes()) {\n                return Ok(encoding);\n            }\n        }\n    }\n\n    Err(anyhow::anyhow!(\n        \"{} is not a supported encoding, please refer to https://encoding.spec.whatwg.org/#names-and-labels \\\n         for supported encodings\",\n        encoding\n    ))\n}\n\n/// Based on the function used by clap to abort\nfn safe_exit() -> ! {\n    let _ = std::io::stdout().lock().flush();\n    let _ = std::io::stderr().lock().flush();\n    std::process::exit(0);\n}\n\nfn long_version() -> &'static str {\n    concat!(env!(\"CARGO_PKG_VERSION\"), \"\\n\", env!(\"XH_FEATURES\"))\n}\n\n#[cfg(test)]","sourceCodeStart":1396,"sourceCodeEnd":1432,"githubUrl":"https://github.com/ducaale/xh/blob/2404aceecc08b0b2d100fedc96f57745cd5904dc/src/cli.rs#L1396-L1432","documentation":"The --encoding argument is validated against the WHATWG Encoding Standard via encoding_rs::Encoding::for_label. If the label doesn't resolve to a known encoding, the parser rejects it and points at the official label list.","triggerScenarios":"Passing --encoding utf8 (not a valid label alone in some contexts), --encoding ascii-8bit, --encoding latin0, or any misspelled/unregistered encoding name.","commonSituations":"Using aliases from other languages (e.g. Python's 'utf-8' works but invented names like 'utf8mb4' or 'win-1252x' do not), assuming all iconv names are supported.","solutions":["Use a WHATWG label exactly, e.g. --encoding utf-8, windows-1252, or iso-8859-1","Check the linked spec page https://encoding.spec.whatwg.org/#names-and-labels for valid labels","Common aliases: use 'latin1' or 'iso-8859-1' instead of 'latin0'; 'gb18030' instead of Chinese variants not in the spec"],"exampleFix":"// before\nxh --encoding utf8mb4 GET https://example.com\n// after\nxh --encoding utf-8 GET https://example.com","handlingStrategy":"validation","validationCode":"fn is_valid_encoding_label(label: &str) -> bool {\n    encoding_rs::Encoding::for_label(label.as_bytes()).is_some()\n}","typeGuard":"fn valid_encoding(label: &str) -> Option<&'static encoding_rs::Encoding> {\n    encoding_rs::Encoding::for_label(label.as_bytes())\n}","tryCatchPattern":"match parse_encoding(&label) {\n    Ok(enc) => enc,\n    Err(e) => eprintln!(\"{e}; use labels like utf-8, windows-1252, iso-8859-1\"),\n}","preventionTips":["Validate labels against encoding_rs::Encoding::for_label before running","Use exact WHATWG labels (utf-8, not utf8mb4)","Consult the spec's names-and-labels table for aliases"],"tags":["cli","encoding","charset","rust"],"backgroundTag":"invalid-config-value","analyzedSha":"2404aceecc08b0b2d100fedc96f57745cd5904dc","analyzedAt":"2026-09-13T19:13:33.814Z","contentChangedAt":"2026-09-13T19:13:33.814Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}