{"record":{"id":"d6391511dd929978","repo":"windmill-labs/windmill","slug":"file-path-is-encoded-as-utf-16-be-which-is-not","errorCode":null,"errorMessage":"File ${path} is encoded as UTF-16 BE, which is not supported. Please convert it to UTF-8.","messagePattern":"File (.+?) is encoded as UTF-16 BE, 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":148,"sourceCode":"): 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\");\n}\n\nexport function stripBom(content: string): string {\n  if (content.charCodeAt(0) === 0xfeff) {\n    return content.slice(1);","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/cli/src/utils/utils.ts#L130-L166","documentation":"Sentinel guard in decodeBufferAsUtf8: the file starts with the UTF-16 BE BOM (FE FF); decoding as UTF-8 would corrupt all content, so the CLI rejects the file instead. The input at fault is the file's encoding.","triggerScenarios":"Reading a file via `readTextFile`/`readTextFileSync` whose first two bytes are FE FF.","commonSituations":"Files produced by tools defaulting to UTF-16BE (some Java/legacy tools), or cross-platform handoffs from big-endian-origin systems.","solutions":["Re-save as UTF-8 in your editor ('Save with Encoding' → UTF-8)","Convert: `iconv -f UTF-16BE -t UTF-8 file > file.tmp && mv file.tmp file`","Python: `open(f,'rb').read().decode('utf-16').encode('utf-8')` written back to disk"],"exampleFix":"// before\nfile raw.yaml  # UTF-16 (with BOM), Big-endian\n// after\niconv -f UTF-16BE -t UTF-8 raw.yaml > /tmp/raw.tmp && mv /tmp/raw.tmp raw.yaml","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nfunction assertNotUtf16Be(path) {\n  const b = fs.readFileSync(path).subarray(0, 2);\n  if (b[0] === 0xfe && b[1] === 0xff)\n    throw new Error(`${path} is UTF-16 BE; convert to UTF-8 first`);\n}","typeGuard":"function isUtf16Be(buf) {\n  return buf.length >= 2 && buf[0] === 0xfe && buf[1] === 0xff;\n}","tryCatchPattern":"try {\n  const content = await readTextFile(path);\n} catch (e) {\n  if (String(e.message).includes('UTF-16 BE')) console.error('Convert with: iconv -f UTF-16BE -t UTF-8 <file>');\n  else throw e;\n}","preventionTips":["Detect BOMs with `xxd -l 2 <file>` or `file` when files come from Java/legacy tools","Normalize all checked-in YAML/JSON to UTF-8 in CI","Keep editor defaults at UTF-8 without cross-encoding round-trips"],"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"}