Skip to content

fix: auto-set errno for int ops returning CHECK_IS_FALSE#79

Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-auto-errno-int-ops
Draft

fix: auto-set errno for int ops returning CHECK_IS_FALSE#79
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-auto-errno-int-ops

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

@Koan-Bot Koan-Bot commented Apr 6, 2026

What

Make _check() auto-set a default errno when int ops (-s, -M, -A, -C) return CHECK_IS_FALSE without the callback having set $!.

Why

The $OP_CAN_RETURN_INT fast-path returned immediately for any defined value, bypassing the auto-errno logic that boolean ops get. This meant returning undef auto-set ENOENT (via CHECK_IS_NULL), but returning CHECK_IS_FALSE left $! at 0 or stale — an observable inconsistency that confuses users checking $! after mocked file tests.

How

Added the same !int($!) guard to the int-op fast-path: when the return is falsy and the callback didn't set errno, apply the default errno (ENOENT for most ops, ENOEXEC for -x/-X).

Testing

  • Added new subtest in t/int-errno-preservation.t covering the exact scenario: -s mock returns CHECK_IS_FALSE without setting $!, verifies ENOENT is auto-set
  • Full test suite passes

Closes #62

🤖 Generated with Claude Code

When a mock for -s/-M/-A/-C returned CHECK_IS_FALSE (0) without
setting $!, the $OP_CAN_RETURN_INT fast-path returned immediately,
bypassing the auto-errno logic that boolean ops get. This left $!
at zero (or stale), creating an observable inconsistency: returning
undef auto-set ENOENT but returning CHECK_IS_FALSE did not.

Add the same !int($!) guard to the int-op fast-path so falsy returns
consistently get a default errno when the callback didn't set one.

Closes cpan-authors#62

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.

robustness: _check() skips auto-errno for OP_CAN_RETURN_INT false returns

1 participant