Fission-AI/OpenSpec · error

File is encoded as UTF-16 BE which is not supported. Please…

Error message

File is encoded as UTF-16 BE which is not supported. Please re-save as UTF-8 or UTF-16 LE, then retry.

What it means

Encoding probe in the PowerShell profile installer: the file's BOM (FE FF) identifies UTF-16 big-endian, which Node cannot encode natively. Because the installer preserves the original encoding on write, it refuses rather than corrupt the profile.

Solutions

  1. Open the PowerShell profile in an editor and re-save it as UTF-8 (or UTF-16 LE with BOM)
  2. Retry the installer after the encoding change
  3. Avoid tools that write PowerShell profiles as UTF-16 BE
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/core/completions/installers/powershell-installer.ts:37 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Fission-AI/OpenSpec@6926ccb18a (2026-08-25). Data as JSON: /api/errors/761632ff7d9245bb. Report an issue: GitHub.

Appendix: source

Thrown at src/core/completions/installers/powershell-installer.ts:37

    end: '# OPENSPEC:END',
  };

  constructor(homeDir: string = os.homedir()) {
    this.homeDir = homeDir;
  }

  /**
   * Detect the encoding of a file by inspecting its BOM (Byte Order Mark).
   * Returns the Node.js BufferEncoding and the raw BOM bytes to preserve on write.
   */
  private detectEncoding(buffer: Buffer): { encoding: BufferEncoding; bom: Buffer } {
    // UTF-16 LE BOM: FF FE
    if (buffer.length >= 2 && buffer[0] === 0xff && buffer[1] === 0xfe) {
      return { encoding: 'utf16le', bom: Buffer.from([0xff, 0xfe]) };
    }
    // UTF-16 BE BOM: FE FF — not natively supported by Node
    if (buffer.length >= 2 && buffer[0] === 0xfe && buffer[1] === 0xff) {
      throw new Error(
        'File is encoded as UTF-16 BE which is not supported. ' +
          'Please re-save as UTF-8 or UTF-16 LE, then retry.',
      );
    }
    // UTF-8 BOM: EF BB BF
    if (buffer.length >= 3 && buffer[0] === 0xef && buffer[1] === 0xbb && buffer[2] === 0xbf) {
      return { encoding: 'utf-8', bom: Buffer.from([0xef, 0xbb, 0xbf]) };
    }
    // No BOM → default UTF-8
    return { encoding: 'utf-8', bom: Buffer.alloc(0) };
  }

  /**
   * Read a profile file, preserving its encoding metadata for round-trip writes.
   * Throws if the file uses UTF-16 BE (unsupported by Node).
   */
  private async readProfileFile(filePath: string): Promise<{ content: string; encoding: BufferEncoding; bom: Buffer }> {
    const raw = await fs.readFile(filePath);

View on GitHub (pinned to 6926ccb18a)