{"record":{"id":"b7fe90767643a917","repo":"windmill-labs/windmill","slug":"file-path-is-encoded-as-utf-16-le-which-is-not","errorCode":null,"errorMessage":"File ${path} is encoded as UTF-16 LE, which is not supported. Please convert it to UTF-8.","messagePattern":"File (.+?) is encoded as UTF-16 LE, which is not supported\\. Please convert it to UTF-8\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/src/utils/utils.ts","lineNumber":143,"sourceCode":"  return await generateHashFromBuffer(messageBuffer);\n}\n\nexport async function generateHashFromBuffer(\n  content: BufferSource\n): Promise<string> {\n  const hashBuffer = await crypto.subtle.digest(\"SHA-256\", content);\n  return Buffer.from(hashBuffer).toString(\"hex\");\n}\n\nfunction decodeBufferAsUtf8(buf: Buffer, path: string | URL): string {\n  if (buf.length >= 2) {\n    if (buf[0] === 0xff && buf[1] === 0xfe) {\n      if (buf.length >= 4 && buf[2] === 0x00 && buf[3] === 0x00) {\n        throw new Error(\n          `File ${path} is encoded as UTF-32 LE, which is not supported. Please convert it to UTF-8.`\n        );\n      }\n      throw new Error(\n        `File ${path} is encoded as UTF-16 LE, which is not supported. Please convert it to UTF-8.`\n      );\n    }\n    if (buf[0] === 0xfe && buf[1] === 0xff) {\n      throw new Error(\n        `File ${path} is encoded as UTF-16 BE, which is not supported. Please convert it to UTF-8.`\n      );\n    }\n    if (buf.length >= 4 && buf[0] === 0x00 && buf[1] === 0x00 && buf[2] === 0xfe && buf[3] === 0xff) {\n      throw new Error(\n        `File ${path} is encoded as UTF-32 BE, which is not supported. Please convert it to UTF-8.`\n      );\n    }\n  }\n  if (buf.length >= 3 && buf[0] === 0xef && buf[1] === 0xbb && buf[2] === 0xbf) {\n    return buf.subarray(3).toString(\"utf-8\");\n  }\n  return buf.toString(\"utf-8\");","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/cli/src/utils/utils.ts#L125-L161","documentation":"Sentinel guard in decodeBufferAsUtf8: the file read starts with the UTF-16 LE BOM (FF FE), so it is not valid UTF-8 and decoding it as UTF-8 would silently corrupt every string parsed from it (scripts, resources, variables). The input at fault is the file's encoding.","triggerScenarios":"Reading a file via `readTextFile`/`readTextFileSync` whose first two bytes are FF FE (and not followed by 00 00).","commonSituations":"Files exported from Windows Notepad ('Unicode' encoding), Excel CSV exports, or PowerShell 5.1 `Out-File` default (UTF-16 LE).","solutions":["Re-save the file as UTF-8 in your editor","Convert: `iconv -f UTF-16LE -t UTF-8 file > file.tmp && mv file.tmp file`","In PowerShell 5.1, pass `-Encoding utf8` to Out-File/Set-Content instead of the default"],"exampleFix":"// before (PowerShell 5.1)\nGet-Content raw.yaml | Set-Content raw.yaml  # UTF-16 LE\n// after\nGet-Content raw.yaml | Set-Content raw.yaml -Encoding utf8","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nfunction assertNotUtf16Le(path) {\n  const b = fs.readFileSync(path).subarray(0, 4);\n  if (b[0] === 0xff && b[1] === 0xfe && !(b[2] === 0x00 && b[3] === 0x00))\n    throw new Error(`${path} is UTF-16 LE; convert to UTF-8 first`);\n}","typeGuard":"function isUtf16Le(buf) {\n  return buf.length >= 2 && buf[0] === 0xff && buf[1] === 0xfe && !(buf.length >= 4 && buf[2] === 0x00 && buf[3] === 0x00);\n}","tryCatchPattern":"try {\n  const content = await readTextFile(path);\n} catch (e) {\n  if (String(e.message).includes('UTF-16 LE')) console.error('Convert with: iconv -f UTF-16LE -t UTF-8 <file>');\n  else throw e;\n}","preventionTips":["PowerShell 5.1 defaults to UTF-16 LE for Out-File/Set-Content — always pass -Encoding utf8","Set editors to save UTF-8 by default (VS Code 'files.encoding': 'utf8')","Run `file <path>` on files produced by Windows tools before committing them to CLI workflows"],"tags":["encoding","utf-16","file","bom"],"backgroundTag":"unsupported-file-encoding","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}