fix: empty CATCH block now catches errors (GH #271)#417
Open
toddr-bot wants to merge 2 commits into
Open
Conversation
An empty CATCH block (no body) should still catch errors and suppress them, but currently the error propagates as if no CATCH existed. These tests will pass once the bug is fixed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
An empty CATCH block like `TRY; ...; CATCH; END` was not catching errors because the empty block produced an empty string, which is falsy in Perl. The `if ($default)` check in Directive::try() treated it as "no default handler", letting the error propagate. Fix: use `defined($default)` to distinguish an empty catch block (empty string) from no catch block at all (undef). Also changed the `$default ||=` assignment to use `defined` check, ensuring an empty default CATCH isn't overridden by a later one. Closes #271 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
|
Recreated from #347 (auto-closed when the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Empty
CATCHblocks (no body) now properly catch and suppress errors.Why
A
TRY; THROW ...; CATCH; ENDconstruct should silently catch the error, but instead the error propagated as if no CATCH existed. This was reported in #271.How
The bug was in
Directive::try()— theif ($default)truthiness check treated an empty block (empty string'') the same as no block at all (undef). Changed toif (defined $default)to distinguish between "catch with empty body" and "no catch at all". Also hardened the$defaultassignment to use adefinedcheck, consistent with Perl 5.8 compatibility.Testing
t/try.tcovering empty default CATCH, empty named CATCH, mixed named+empty default, and empty catch-all after unmatched named handler.Closes #271
🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 45 insertions(+), 2 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline