Skip to content

Conversation

@rcosta358
Copy link
Collaborator

@rcosta358 rcosta358 commented Feb 5, 2026

This PR adds support for custom messages in refinements and state refinements, through an extra parameter msg:

@Refinement(value="...", msg="...")
@StateRefinement(from="...", to="...", msg="...")

Examples

image image image

In the last example, the close method is annotated with two state refinements, each with its own message, so both are shown. However, to simplify the error message, users should specify a message in only one of them, e.g., "The buffered reader should be open or marked to be closed".

@rcosta358 rcosta358 self-assigned this Feb 5, 2026
@rcosta358 rcosta358 added enhancement New feature or request error messages labels Feb 5, 2026
@rcosta358 rcosta358 changed the title Add Custom Messages Add Custom Messages to Errors Feb 5, 2026
@rcosta358 rcosta358 changed the title Add Custom Messages to Errors Add Custom Error Messages Feb 7, 2026
Copy link
Collaborator

@CatarinaGamboa CatarinaGamboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a couple of comments but you can address them in a follow up pr!
also add a couple of tests with the new feature


public String value();

public String msg() default "";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add documentation to all these fields in a follow up pr


public String to() default "";

public String msg() default "";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add documentation here to and say that this msg should be for when the from is violated


// calculate padding for line numbers
int padding = String.valueOf(endLine).length();
String pipe = " | ";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets use a static final with caps lock to represent the pipe

@rcosta358 rcosta358 merged commit 62a28a3 into main Feb 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request error messages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants