Skip to content

fix: PRINT/PRINTF return false when weakened data ref is gone#283

Draft
Koan-Bot wants to merge 1 commit intocpanel:masterfrom
atoomic:koan.atoomic/fix-print-printf-weakref-return
Draft

fix: PRINT/PRINTF return false when weakened data ref is gone#283
Koan-Bot wants to merge 1 commit intocpanel:masterfrom
atoomic:koan.atoomic/fix-print-printf-weakref-return

Conversation

@Koan-Bot
Copy link
Contributor

@Koan-Bot Koan-Bot commented Mar 3, 2026

What

PRINT and PRINTF now check _write_bytes() return value instead of unconditionally returning 1.

Why

When a mock is destroyed while a filehandle is still open, the weakened data ref becomes undef. _write_bytes() correctly returns 0 with $! = EBADF in this case, but PRINT/PRINTF ignored the failure and returned 1 (success). WRITE already handled this correctly — this aligns PRINT/PRINTF with the same pattern.

How

  • Check _write_bytes() return; only call _update_write_times() when bytes were written
  • Return $bytes ? 1 : 0 to match PRINT/PRINTF's boolean contract (vs WRITE's byte-count contract)
  • Added tests for both print and printf after mock destruction, verifying false return and EBADF errno

Testing

  • Updated t/filehandle_weakref.t: existing print subtest now asserts return value and errno; new printf subtest added

🤖 Generated with Claude Code

PRINT and PRINTF always returned 1 (success) even when _write_bytes()
failed because the mock was destroyed and the weakened data ref became
undef. WRITE already handled this correctly by checking the return
value. Apply the same pattern to PRINT and PRINTF for consistency.

Also skips _update_write_times() when no bytes were written, matching
WRITE's existing behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant