Skip to content

fix: correct error returns in tied handle methods - #415

Draft
toddr-bot wants to merge 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-issue-351
Draft

fix: correct error returns in tied handle methods#415
toddr-bot wants to merge 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-issue-351

Conversation

@toddr-bot

@toddr-bot toddr-bot commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

What

Fix incorrect error return values in WRITE, READ, GETC, and READLINE tied handle methods.

Why

Real Perl syswrite returns undef on error (EBADF, EINVAL), where 0 means "zero bytes written". The tied WRITE method was returning 0 for all error conditions, making errors indistinguishable from successful zero-byte writes when checking defined(syswrite(...)). Same issue in READ for the data-gone (weakref destroyed) case. Additionally, getc and readline on write-only handles were warning correctly but not setting $! = EBADF, diverging from real Perl behavior.

How

  • WRITE: all 4 error returns changed from 0 to undef (EBADF, EINVAL × 3)
  • _write_bytes: data-gone return changed from 0 to undef
  • READ: data-gone return changed from 0 to undef
  • GETC: added $! = EBADF before return on write-only handle
  • READLINE: added $! = EBADF before return on write-only handle

Testing

  • Updated 11 existing test assertions across 5 test files to expect undef instead of 0
  • Added 3 new $! = EBADF assertions for readline (scalar + list) and getc on write-only handles
  • Full suite: 1589 tests pass (3 pre-existing failures in fh-ref-leak.t, unrelated)

Closes #351


Quality Report

Changes: 7 files changed, 30 insertions(+), 22 deletions(-)

Code scan: clean

Tests: failed (4 Failed, 94 test)

Branch hygiene: clean

Generated by Kōan

WRITE (syswrite) now returns undef on all error conditions instead of 0,
matching real Perl behavior where undef signals error and 0 means zero
bytes written. READ (sysread) data-gone case also corrected.

GETC and READLINE on write-only handles now set $! = EBADF in addition
to warning, matching real Perl's errno behavior.

Closes cpan-authors#351
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: syswrite/sysread return 0 instead of undef on error; getc/readline miss $!=EBADF

1 participant