Skip to content

fix: set errno consistently in tied handle methods#395

Draft
Koan-Bot wants to merge 1 commit into
cpan-authors:mainfrom
atoomic:koan.atoomic/fix-errno-consistency
Draft

fix: set errno consistently in tied handle methods#395
Koan-Bot wants to merge 1 commit into
cpan-authors:mainfrom
atoomic:koan.atoomic/fix-errno-consistency

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

@Koan-Bot Koan-Bot commented May 12, 2026

What

Fix three missing errno assignments in FileHandle.pm tied methods — SEEK, GETC, and READLINE now correctly set $! on error, matching the behavior of READ, WRITE, PRINT, and PRINTF.

Why

Some tied methods (READ, WRITE, PRINT) already set $! on permission/error paths, but SEEK, GETC, and READLINE were missed. Code under test that checks $! after a failed seek/getc/readline would see stale errno values from mocked handles, potentially masking bugs.

Closes #342.

How

  • SEEK: Add $! = EINVAL before returning 0 on negative position (1 line)
  • GETC: Add $! = EBADF when called on write-only handle (1 line)
  • READLINE: Add $! = EBADF when called on write-only handle (1 line)

All three follow the existing pattern used by READ/WRITE/PRINT in the same file.

Testing

  • Updated t/seek.t: verify EINVAL on negative seeks (SEEK_SET, SEEK_CUR, SEEK_END) + failed builtin seek() preserves tell position
  • Updated t/readline.t: verify EBADF on write-only readline() (scalar + list context) and getc()
  • Full test suite passes locally

🤖 Generated with Claude Code


Quality Report

Changes: 3 files changed, 21 insertions(+)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

Three errno bugs in FileHandle.pm:

1. SEEK: missing $! = EINVAL when seeking to a negative position
   (closes cpan-authors#342). Real Perl's seek/sysseek sets EINVAL on failure.

2. GETC: missing $! = EBADF when called on a write-only handle.
   READ and WRITE already set EBADF correctly; GETC was missed.

3. READLINE: missing $! = EBADF when called on a write-only handle.
   Same inconsistency as GETC — the warning was emitted but errno
   was not set.

Tests updated to verify errno is set in all three cases.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: seek() to negative position doesn't set $! to EINVAL

1 participant