cloudflare / cloudflare/workerd

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

Open
#6,817 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
8.7k
Forks
739
Avg merge
2d 20h
Merged PRs (30d)
174

Description

## 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:

```typescript
class MyDO extends DurableObject {
myMethod() {
throw new Error("RESOURCE_NOT_FOUND|->资源不存在");
}
}
```

2. Call this method via RPC (the caller catches the error properly via `mightFail` / try-catch)
3. 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.