@@ -11,15 +11,17 @@ public class LJDiagnostic extends RuntimeException {
1111 private final String title ;
1212 private final String message ;
1313 private final String accentColor ;
14+ private final String customMessage ;
1415 private String file ;
1516 private ErrorPosition position ;
1617
17- public LJDiagnostic (String title , String message , SourcePosition pos , String accentColor ) {
18+ public LJDiagnostic (String title , String message , SourcePosition pos , String accentColor , String customMessage ) {
1819 this .title = title ;
1920 this .message = message ;
2021 this .file = (pos != null && pos .getFile () != null ) ? pos .getFile ().getPath () : null ;
2122 this .position = ErrorPosition .fromSpoonPosition (pos );
2223 this .accentColor = accentColor ;
24+ this .customMessage = customMessage ;
2325 }
2426
2527 public String getTitle () {
@@ -30,6 +32,10 @@ public String getMessage() {
3032 return message ;
3133 }
3234
35+ public String getCustomMessage () {
36+ return customMessage ;
37+ }
38+
3339 public String getDetails () {
3440 return "" ; // to be overridden by subclasses
3541 }
@@ -115,8 +121,15 @@ public String getSnippet() {
115121 // line number padding + " | " + column offset
116122 String indent = " " .repeat (padding ) + Colors .GREY + " | " + Colors .RESET
117123 + " " .repeat (colStart - 1 );
118- String markers = accentColor + "^" .repeat (Math .max (1 , colEnd - colStart + 1 )) + Colors .RESET ;
119- sb .append (indent ).append (markers ).append ("\n " );
124+ String markers = accentColor + "^" .repeat (Math .max (1 , colEnd - colStart + 1 ));
125+ sb .append (indent ).append (markers );
126+
127+ // custom message
128+ if (customMessage != null && !customMessage .isBlank ()) {
129+ sb .append (" " + customMessage );
130+ }
131+
132+ sb .append (Colors .RESET ).append ("\n " );
120133 }
121134 }
122135 }
0 commit comments