Skip to content

Conversation

@kfly8
Copy link
Owner

@kfly8 kfly8 commented Dec 20, 2024

Problem

When an assertion fails, the default error message (e.g., Assertion failed (0 == 1)) may not clearly explain what went wrong.

Solution

Allow users to provide a custom error message as the second argument:

assert($x > 0, "x must be positive");
# => x must be positive

assert($user->is_authenticated, "User must be logged in");
# => User must be logged in

This makes it easier to understand the context of the failure without inspecting the code.

@coveralls
Copy link

coveralls commented Dec 20, 2024

Pull Request Test Coverage Report for Build 20029366737

Details

  • 59 of 61 (96.72%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.4%) to 85.202%

Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/Syntax/Keyword/Assert.xs 57 59 96.61%
Totals Coverage Status
Change from base Build 20005013373: 0.4%
Covered Lines: 190
Relevant Lines: 223

💛 - Coveralls

@kfly8 kfly8 changed the title Added parser setting Custom error message Dec 22, 2024
@kfly8 kfly8 changed the title Custom error message Custom error messages Dec 22, 2024
kfly8 and others added 4 commits December 7, 2025 22:36
Allow users to provide a custom error message as the second argument:

  assert($x > 0, "x must be positive");

When the assertion fails, the custom message is displayed instead of
the auto-generated one. This is useful when the default message
(e.g., "Assertion failed (0 > 0)") is not descriptive enough.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@kfly8 kfly8 marked this pull request as ready for review December 8, 2025 13:15
@kfly8 kfly8 changed the title Custom error messages Add custom error message support Dec 8, 2025
@kfly8 kfly8 merged commit 81207ab into main Dec 8, 2025
14 checks passed
@kfly8 kfly8 deleted the error-message branch December 8, 2025 13:23
kfly8 added a commit that referenced this pull request Dec 8, 2025
Changelog diff is:

diff --git a/Changes b/Changes
index 960d9de..b9e7aba 100644
--- a/Changes
+++ b/Changes
@@ -2,6 +2,10 @@ Revision history for Perl extension Syntax-Keyword-Assert
 
 {{$NEXT}}
 
+0.17 2025-12-08T13:44:46Z
+    - Add custom error message support #11
+    - Fix test failures on Windows and older Perl #13
+
 0.16 2024-12-18T09:01:18Z
     - Fixed `isa` operator #9
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.

3 participants