{"record":{"id":"e6e07d487c52030c","repo":"helix-editor/helix","slug":"unknown-encoding","errorCode":null,"errorMessage":"unknown encoding","messagePattern":"unknown encoding","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"helix-view/src/document.rs","lineNumber":1326,"sourceCode":"        self.append_changes_to_history(view);\n        self.reset_modified();\n        self.pickup_last_saved_time();\n        self.detect_indent_and_line_ending();\n\n        match provider_registry.get_diff_base(&path, trust_full) {\n            Some(diff_base) => self.set_diff_base(diff_base),\n            None => self.diff_handle = None,\n        }\n\n        self.version_control_head = provider_registry.get_current_head_name(&path, trust_full);\n\n        Ok(())\n    }\n\n    /// Sets the [`Document`]'s encoding with the encoding correspondent to `label`.\n    pub fn set_encoding(&mut self, label: &str) -> Result<(), Error> {\n        let encoding =\n            Encoding::for_label(label.as_bytes()).ok_or_else(|| anyhow!(\"unknown encoding\"))?;\n\n        self.encoding = encoding;\n\n        Ok(())\n    }\n\n    /// Returns the [`Document`]'s current encoding.\n    pub fn encoding(&self) -> &'static Encoding {\n        self.encoding\n    }\n\n    /// sets the document path without sending events to various\n    /// observers (like LSP), in most cases `Editor::set_doc_path`\n    /// should be used instead\n    pub fn set_path(&mut self, path: Option<&Path>) {\n        let path = path.map(helix_stdx::path::canonicalize);\n\n        // `take` to remove any prior relative path that may have existed.","sourceCodeStart":1308,"sourceCodeEnd":1344,"githubUrl":"https://github.com/helix-editor/helix/blob/079a789e8cb08ead67f19e1971a1b7438b37354b/helix-view/src/document.rs#L1308-L1344","documentation":"Document::set_encoding resolves the given label with encoding_rs::Encoding::for_label, which only accepts labels from the WHATWG Encoding Standard (e.g. \"utf-8\", \"utf-16le\", \"windows-1252\"). If the label matches none of them, for_label returns None and the method bails with \"unknown encoding\". This is the path behind Helix's :set-encoding command and encoding-related reloads.","triggerScenarios":"Calling doc.set_encoding(label) with a string that is not a WHATWG label: typos (\"utf-88\"), colloquial names (\"unicode\", \"ansi\"), or an encoding name that exists under IANA but not under the WHATWG label table. Also triggered by config or scripted callers that pass user input straight through without validation.","commonSituations":"A user types :set-encoding unicode or :set-encoding ascii expecting them to work; a config or script hardcodes an encoding name from a different spec; case or dash variants are fine for many labels but a genuinely unknown name reaches this branch.","solutions":["Use a WHATWG-recognized label: \"utf-8\", \"utf-16le\", \"utf-16be\", \"latin1\" (windows-1252), \"gbk\", \"shift_jis\", etc.","If unsure, validate the label first with encoding_rs::Encoding::for_label(label.as_bytes()); None means Helix will also reject it.","Check the WHATWG Encoding Standard label table for the exact alias list before hardcoding a name."],"exampleFix":"// before\n doc.set_encoding(\"unicode\")?; // Err: unknown encoding\n\n// after\n let label = \"utf-8\";\n debug_assert!(encoding_rs::Encoding::for_label(label.as_bytes()).is_some());\n doc.set_encoding(label)?;","handlingStrategy":"validation","validationCode":"fn is_known_encoding(label: &str) -> bool {\n    encoding_rs::Encoding::for_label(label.as_bytes()).is_some()\n}\n\n// before saving:\nif !is_known_encoding(label) {\n    return Err(anyhow!(\"unsupported encoding label '{label}'\"));\n}\ndoc.set_encoding(label)?;","typeGuard":"fn resolve_encoding(label: &str) -> Option<&'static encoding_rs::Encoding> {\n    encoding_rs::Encoding::for_label(label.as_bytes())\n}","tryCatchPattern":"if let Err(err) = doc.set_encoding(label) {\n    // error is context-free (\"unknown encoding\"), so re-wrap with the label\n    log::warn!(\"set_encoding('{label}') failed: {err:#}\");\n    editor.set_error(format!(\"unknown encoding '{label}'\"));\n}","preventionTips":["Validate labels with Encoding::for_label before calling set_encoding.","Offer completion sourced from the WHATWG label list in any UI that prompts for an encoding.","Never pass free-form user text straight into set_encoding."],"tags":["encoding","document","helix","rust"],"backgroundTag":null,"analyzedSha":"079a789e8cb08ead67f19e1971a1b7438b37354b","analyzedAt":"2026-08-16T09:09:59.668Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}