windmill-labs/windmill · error

File ${path} is encoded as UTF-16 BE, which is not supported

Error message

File ${path} is encoded as UTF-16 BE, which is not supported. Please convert it to UTF-8.

What it means

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.

Source

Thrown at cli/src/utils/utils.ts:148

): Promise<string> {
  const hashBuffer = await crypto.subtle.digest("SHA-256", content);
  return Buffer.from(hashBuffer).toString("hex");
}

function decodeBufferAsUtf8(buf: Buffer, path: string | URL): string {
  if (buf.length >= 2) {
    if (buf[0] === 0xff && buf[1] === 0xfe) {
      if (buf.length >= 4 && buf[2] === 0x00 && buf[3] === 0x00) {
        throw new Error(
          `File ${path} is encoded as UTF-32 LE, which is not supported. Please convert it to UTF-8.`
        );
      }
      throw new Error(
        `File ${path} is encoded as UTF-16 LE, which is not supported. Please convert it to UTF-8.`
      );
    }
    if (buf[0] === 0xfe && buf[1] === 0xff) {
      throw new Error(
        `File ${path} is encoded as UTF-16 BE, which is not supported. Please convert it to UTF-8.`
      );
    }
    if (buf.length >= 4 && buf[0] === 0x00 && buf[1] === 0x00 && buf[2] === 0xfe && buf[3] === 0xff) {
      throw new Error(
        `File ${path} is encoded as UTF-32 BE, which is not supported. Please convert it to UTF-8.`
      );
    }
  }
  if (buf.length >= 3 && buf[0] === 0xef && buf[1] === 0xbb && buf[2] === 0xbf) {
    return buf.subarray(3).toString("utf-8");
  }
  return buf.toString("utf-8");
}

export function stripBom(content: string): string {
  if (content.charCodeAt(0) === 0xfeff) {
    return content.slice(1);

View on GitHub (pinned to e474e8803c)

Solutions

  1. Re-save as UTF-8 in your editor ('Save with Encoding' → UTF-8)
  2. Convert: `iconv -f UTF-16BE -t UTF-8 file > file.tmp && mv file.tmp file`
  3. Python: `open(f,'rb').read().decode('utf-16').encode('utf-8')` written back to disk

Example fix

// before
file raw.yaml  # UTF-16 (with BOM), Big-endian
// after
iconv -f UTF-16BE -t UTF-8 raw.yaml > /tmp/raw.tmp && mv /tmp/raw.tmp raw.yaml
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
function assertNotUtf16Be(path) {
  const b = fs.readFileSync(path).subarray(0, 2);
  if (b[0] === 0xfe && b[1] === 0xff)
    throw new Error(`${path} is UTF-16 BE; convert to UTF-8 first`);
}

Type guard

function isUtf16Be(buf) {
  return buf.length >= 2 && buf[0] === 0xfe && buf[1] === 0xff;
}

Try / catch

try {
  const content = await readTextFile(path);
} catch (e) {
  if (String(e.message).includes('UTF-16 BE')) console.error('Convert with: iconv -f UTF-16BE -t UTF-8 <file>');
  else throw e;
}

Prevention

When it happens

Trigger: Reading a file via `readTextFile`/`readTextFileSync` whose first two bytes are FE FF.

Common situations: Files produced by tools defaulting to UTF-16BE (some Java/legacy tools), or cross-platform handoffs from big-endian-origin systems.

Related errors


AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03). Data as JSON: /api/errors/d6391511dd929978. Report an issue: GitHub.