mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
## Summary - Fixed a debug build assertion failure in PostgreSQL error handling when all error message fields are empty - Added safety check before calling `StringBuilder.allocatedSlice()` to handle zero-length messages - Added regression test to prevent future occurrences ## The Problem When PostgreSQL sends an error response with completely empty message fields, the `ErrorResponse.toJS` function would: 1. Calculate `b.cap` but end up with `b.len = 0` (no actual content) 2. Call `b.allocatedSlice()[0..b.len]` unconditionally 3. Trigger an assertion in `StringBuilder.allocatedSlice()` that requires `cap > 0` This only affected debug builds since the assertion is compiled out in release builds. ## The Fix Check if `b.len > 0` before calling `allocatedSlice()`. If there's no content, use an empty string instead. ## Test Plan - [x] Added regression test that triggers the exact crash scenario - [x] Verified test crashes without the fix (debug build) - [x] Verified test passes with the fix - [x] Confirmed release builds were not affected 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>