{"record":{"id":"9bad573ba92fd7f8","repo":"siyuan-note/siyuan","slug":"only-utf-8-text-files-can-be-edited","errorCode":null,"errorMessage":"only UTF-8 text files can be edited","messagePattern":"only UTF-8 text files can be edited","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/util/skill_manage.go","lineNumber":31,"sourceCode":"\t\"os\"\n\t\"path\"\n\t\"path/filepath\"\n\t\"strings\"\n\t\"sync\"\n\t\"unicode\"\n\t\"unicode/utf8\"\n\n\t\"github.com/88250/lute/ast\"\n\t\"github.com/siyuan-note/filelock\"\n)\n\nconst maxManagedSkillSourceSize = 8 * 1024 * 1024\n\nvar skillManagementLock sync.Mutex\n\nvar (\n\tErrSkillBinary   = errors.New(\"binary files cannot be edited as text\")\n\tErrSkillEncoding = errors.New(\"only UTF-8 text files can be edited\")\n\tErrSkillTooLarge = errors.New(\"text files must be at most 8 MiB\")\n)\n\ntype SkillFileRequest struct {\n\tAction   string\n\tPath     string\n\tTarget   string\n\tContent  string\n\tRevision string\n}\n\ntype SkillFileEntry struct {\n\tPath     string\n\tIsDir    bool\n\tEditable bool\n}\n\ntype SkillFileData struct {","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/skill_manage.go#L13-L49","documentation":"ErrSkillEncoding indicates the file content is not valid UTF-8 text: either it starts with a UTF-16/UTF-32 BOM (\\xff\\xfe, \\xfe\\xff, \\x00\\x00\\xfe\\xff) or utf8.ValidString fails. The skill editor only supports UTF-8 text, so such files are rejected on read and write instead of being silently mangled.","triggerScenarios":"Reading/writing a skill file saved as UTF-16 (with BOM) or containing invalid UTF-8 byte sequences; validateManagedSkillSource rejects it in ManageSkillFiles.","commonSituations":"Editing SKILL.md on Windows with a UTF-16-capable editor; PowerShell 5's Out-File defaulting to UTF-16LE; copying content from a binary/legacy-encoded source.","solutions":["Re-save the file as UTF-8 (without UTF-16/UTF-32 BOM) using the editor's encoding option","Convert in place: iconv -f UTF-16 -t UTF-8 file.md > out.md, then replace the original","In PowerShell use utf8 encoding: Out-File -Encoding utf8"],"exampleFix":"// before (PowerShell 5)\nGet-Content a.md | Out-File SKILL.md   # UTF-16LE\n\n// after\nGet-Content a.md | Out-File SKILL.md -Encoding utf8\n","handlingStrategy":"validation","validationCode":"function isUtf8WithoutBOM(bytes) {\n  if (bytes[0] === 0xff && bytes[1] === 0xfe) return false;\n  if (bytes[0] === 0xfe && bytes[1] === 0xff) return false;\n  try { new TextDecoder('utf-8', {fatal: true}).decode(bytes); return true; }\n  catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await api.manageSkillFiles({action: 'write', path, content});\n} catch (e) {\n  if (e.message.includes('only UTF-8')) {\n    // convert file encoding to UTF-8 before retry\n  }\n}","preventionTips":["Configure editors to save as UTF-8 by default","On Windows avoid PowerShell 5 Out-File default (UTF-16LE); use -Encoding utf8","Strip UTF-16/UTF-32 BOMs before writing"],"tags":["encoding","utf-8","skill-editor","go"],"backgroundTag":"unsupported-operation","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}