Skip to content

Garbled Unicode when logging Error.message with non-ASCII characters (e.g. Chinese UTF-8) #6817

Description

@powfan

Description

When a Durable Object method throws an Error whose message contains non-ASCII characters (e.g. Chinese UTF-8), wrangler dev displays garbled/corrupted text in the terminal.

Steps to reproduce

  1. Create a Durable Object with a method that throws an Error with Chinese characters:
class MyDO extends DurableObject {
  myMethod() {
    throw new Error("RESOURCE_NOT_FOUND|->资源不存在");
  }
}
  1. Call this method via RPC (the caller catches the error properly via mightFail / try-catch)
  2. Observe the terminal output in wrangler dev

Expected behavior

✘ [ERROR] RESOURCE_NOT_FOUND|->资源不存在 Error
    at myMethod (file:///path/to/file.ts:3:11)

Actual behavior

✘ [ERROR] ᆲ唕饞몐Ѐ Error
    at value (file:///path/to/file.ts:3:11)

The error message is garbled — Chinese UTF-8 bytes are displayed as wrong Unicode codepoints. The ASCII Error suffix at the end displays correctly.

Other examples of garbled output observed:

  • ꨠۥ詠齙 (should be a validation error message)
  • 귕嚏对琀 (should be a duplicate name error message)

Analysis

The garbled characters are NOT the result of simple latin1 or UTF-16LE misinterpretation of UTF-8 bytes (we verified this). It appears to be a deeper encoding issue in workerd's C++ error logging layer.

Notes

  • The RPC error propagation works correctly — the caller receives the full error message with proper encoding
  • This is purely a display issue in wrangler dev terminal output
  • Only affects the ✘ [ERROR] log lines that workerd prints for exceptions in DO methods
  • ASCII-only error messages display correctly

Environment

  • wrangler 4.99.0
  • macOS (Darwin 25.4.0)
  • Terminal: zsh with UTF-8 locale

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions