windmill-labs/windmill · error

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

Error message

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

What it means

Sentinel guard in decodeBufferAsUtf8: the file starts with the UTF-32 BE BOM (00 00 FE FF); the CLI only accepts UTF-8, so reading is refused rather than producing mojibake. The input at fault is the file's encoding.

Source

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

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);
  }
  return content;
}

export async function readTextFile(path: string | URL): Promise<string> {

View on GitHub (pinned to e474e8803c)

Solutions

  1. Re-save the file as UTF-8
  2. Convert: `iconv -f UTF-32BE -t UTF-8 file > file.tmp && mv file.tmp file`
  3. Verify with `file <path>` that the result is now 'UTF-8 Unicode text'

Example fix

// before
file f.yaml  # data
// after
iconv -f UTF-32BE -t UTF-8 f.yaml > /tmp/f.tmp && mv /tmp/f.tmp f.yaml
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

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

Try / catch

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

Prevention

When it happens

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

Common situations: Files exported by tools that default to UTF-32 (rare, e.g. some Unix utilities or misconfigured converters); files corrupted during encoding conversion.

Related errors


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