{"record":{"id":"01f810851a0858ca","repo":"twpayne/chezmoi","slug":"s-unknown-encoding","errorCode":null,"errorMessage":"%s: unknown encoding","messagePattern":"(.+?): unknown encoding","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/chezmoi/template.go","lineNumber":167,"sourceCode":"\t\t\tkey := string(keyValuePairMatch[1])\n\t\t\tvalue := maybeUnquote(string(keyValuePairMatch[2]))\n\t\t\tswitch key {\n\t\t\tcase \"encoding\":\n\t\t\t\tswitch value {\n\t\t\t\tcase \"utf-8\":\n\t\t\t\t\to.Encoding = unicode.UTF8\n\t\t\t\tcase \"utf-8-bom\":\n\t\t\t\t\to.Encoding = unicode.UTF8BOM\n\t\t\t\tcase \"utf-16-be\":\n\t\t\t\t\to.Encoding = unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM)\n\t\t\t\tcase \"utf-16-be-bom\":\n\t\t\t\t\to.Encoding = unicode.UTF16(unicode.BigEndian, unicode.UseBOM)\n\t\t\t\tcase \"utf-16-le\":\n\t\t\t\t\to.Encoding = unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM)\n\t\t\t\tcase \"utf-16-le-bom\":\n\t\t\t\t\to.Encoding = unicode.UTF16(unicode.LittleEndian, unicode.UseBOM)\n\t\t\t\tdefault:\n\t\t\t\t\treturn nil, fmt.Errorf(\"%s: unknown encoding\", value)\n\t\t\t\t}\n\t\t\tcase \"format-indent\":\n\t\t\t\to.FormatIndent = value\n\t\t\tcase \"format-indent-width\":\n\t\t\t\tswitch width, err := strconv.Atoi(value); {\n\t\t\t\tcase err != nil:\n\t\t\t\t\treturn nil, err\n\t\t\t\tcase width < 0:\n\t\t\t\t\treturn nil, fmt.Errorf(\"%d: invalid format-indent-width\", width)\n\t\t\t\tdefault:\n\t\t\t\t\to.FormatIndent = strings.Repeat(\" \", width)\n\t\t\t\t}\n\t\t\tcase \"left-delimiter\":\n\t\t\t\to.LeftDelimiter = value\n\t\t\tcase \"line-ending\", \"line-endings\":\n\t\t\t\tswitch string(keyValuePairMatch[2]) {\n\t\t\t\tcase \"crlf\":\n\t\t\t\t\to.LineEnding = \"\\r\\n\"","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/twpayne/chezmoi/blob/f901167e4685db90da56d6a2a19df642cb3e0247/internal/chezmoi/template.go#L149-L185","documentation":"This error is raised by chezmoi's template fimodule (internal/chezmoi/template.go:167) when an operation requests an encoding by name and the supplied string does not match any encoding known to that component. The message '%s: unknown encoding' identifies the offending name. In chezmoi this commonly happens with functions like encodeTemplateData/decrypt/encrypt-style helpers or .chezmoitemplate features that take a scheme argument (for example a base64/hex-style encoding name) where the value provided is misspelled, uses the wrong case, or is not supported by the fimodule's registered set. To fix it, check the ficode that passes the encoding name — usually in a template expression in your .chezmoi templates or .chezmoi.toml.tmpl — and replace the invalid value with one of the supported encoding names documented for that function (e.g. the accepted literal such as \"base64\").","triggerScenarios":"A template contains a directive like {{- /* encoding: utf-8-bom */ -}} or another misspelled/unsupported encoding name, hitting the default branch in parseAndRemoveDirectives.","commonSituations":"Misspelling e.g. 'utf-16le' instead of 'utf-16-le'; assuming arbitrary Go IANA encoding names are accepted; copying directives from other tooling with different naming conventions.","solutions":["Use one of the supported values: utf-8, utf-16, utf-16-be, utf-16-be-bom, utf-16-le, utf-16-le-bom","Fix spelling/dashes (e.g. utf-16-le not utf16le or utf-16LE)","Remove the encoding directive if default UTF-8 output is acceptable"],"exampleFix":"// before\n{{- /* encoding: utf-16LE */ -}}\n// after\n{{- /* encoding: utf-16-le */ -}}","handlingStrategy":"validation","validationCode":"// validate encoding directive value against supported set\nallowed := map[string]bool{\n  \"utf-8\": true, \"utf-16\": true, \"utf-16-be\": true, \"utf-16-be-bom\": true,\n  \"utf-16-le\": true, \"utf-16-le-bom\": true,\n}\nif !allowed[value] { return fmt.Errorf(\"unsupported encoding %q\", value) }","typeGuard":"func isKnownEncoding(v string) bool {\n  switch v {\n  case \"utf-8\", \"utf-16\", \"utf-16-be\", \"utf-16-be-bom\", \"utf-16-le\", \"utf-16-le-bom\":\n    return true\n  }\n  return false\n}","tryCatchPattern":"tmpl, err := ParseTemplate(...)\nif err != nil && strings.Contains(err.Error(), \"unknown encoding\") {\n  return fmt.Errorf(\"use a supported encoding directive value (utf-8, utf-16, utf-16-be[-bom], utf-16-le[-bom]): %w\", err)\n}","preventionTips":["Only use the documented encoding names with exact dashes","Prefer omitting the directive when UTF-8 output is fine","Validate templates with chezmoi execute-template in CI"],"tags":["chezmoi","template","encoding"],"backgroundTag":"unknown-encoding","analyzedSha":"f901167e4685db90da56d6a2a19df642cb3e0247","analyzedAt":"2026-09-01T18:16:41.508Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}