Skip to content

Commit 31e6e13

Browse files
committed
Introduce error codes core
1 parent ec9f37f commit 31e6e13

File tree

4 files changed

+368
-3
lines changed

4 files changed

+368
-3
lines changed

core/esmf-aspect-model-validator/src/main/java/org/eclipse/esmf/aspectmodel/validation/services/DetailedViolationFormatter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ private String formatViolation( final Violation violation, final Supplier<String
141141
builder.append( String.format( " - %s%n", fix.description() ) );
142142
}
143143
}
144+
// Add documentation link
145+
builder.append( " documentation: https://eclipse-esmf.github.io/esmf-developer-guide/tooling-guide/error-codes.html"
146+
+ violation.errorCode().toLowerCase().replace( "_", "-" ) );
144147
builder.append( indent( additionalAttributesSupplier.get(), 2 ) );
145148
if ( violation.context() != null ) {
146149
builder.append( String.format( " caused-by-shape:%n" ) );

core/esmf-aspect-model-validator/src/main/java/org/eclipse/esmf/aspectmodel/validation/services/ViolationFormatter.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,17 @@ public String apply( final List<Violation> violations ) {
8484
final List<Violation> elementViolations = entry.getValue();
8585
builder.append( String.format( "> %s :%n", textFormatter.formatName( elementName ) ) );
8686
for ( final Violation violation : elementViolations ) {
87+
// Include error code in the violation message
88+
final String errorCode = violation.errorCode();
89+
final String enhancedMessage = String.format( "[%s] %s", errorCode, violation.message() );
8790
builder.append( indent( violation.accept( this ), 2 ) ).append( System.lineSeparator() );
8891
for ( final Fix possibleFix : violation.fixes() ) {
8992
builder.append( " > Possible fix: " )
9093
.append( possibleFix.description() );
9194
}
95+
// Add documentation link
96+
builder.append( String.format( " > For more information, see: https://eclipse-esmf.github.io/esmf-sdk/tooling-guide/error-codes.html#%s%n",
97+
errorCode.toLowerCase().replace( "_", "-" ) ) );
9298
builder.append( System.lineSeparator() );
9399
}
94100
builder.append( System.lineSeparator() );
@@ -98,10 +104,20 @@ public String apply( final List<Violation> violations ) {
98104
if ( violation instanceof final ProcessingViolation processingViolation ) {
99105
builder.append( processingViolation.accept( this ) );
100106
} else if ( violation.violationSpecificMessage() == null || violation.violationSpecificMessage().equals( violation.message() ) ) {
101-
builder.append( String.format( "> %s%n", violation.message() ) );
107+
final String errorCode = violation.errorCode();
108+
final String enhancedMessage = String.format( "[%s] %s", errorCode, violation.message() );
109+
builder.append( String.format( "> %s%n", enhancedMessage ) );
110+
// Add documentation link for context-free violations
111+
builder.append( " > For more information, see: documentation: https://eclipse-esmf.github.io/esmf-developer-guide/tooling-guide/error-codes.html"
112+
+ errorCode.toLowerCase().replace( "_", "-" ) );
102113
} else {
103-
builder.append( String.format( "> %s: %n", violation.message() ) );
114+
final String errorCode = violation.errorCode();
115+
final String enhancedMessage = String.format( "[%s] %s", errorCode, violation.message() );
116+
builder.append( String.format( "> %s: %n", enhancedMessage ) );
104117
builder.append( indent( violation.accept( this ), 2 ) ).append( System.lineSeparator() );
118+
// Add documentation link
119+
builder.append( " > For more information, see: documentation: https://eclipse-esmf.github.io/esmf-developer-guide/tooling-guide/error-codes.html"
120+
+ errorCode.toLowerCase().replace( "_", "-" ) );
105121
}
106122
builder.append( System.lineSeparator() );
107123
}
@@ -111,7 +127,9 @@ public String apply( final List<Violation> violations ) {
111127

112128
@Override
113129
public String visit( final Violation violation ) {
114-
return formatter.constructDetailedMessage( violation.highlight(), violation.message(), violation.context().element().getModel() );
130+
final String errorCode = violation.errorCode();
131+
final String enhancedMessage = String.format( "[%s] %s", errorCode, violation.message() );
132+
return formatter.constructDetailedMessage( violation.highlight(), enhancedMessage, violation.context().element().getModel() );
115133
}
116134

117135
@Override
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
* xref:samm-cli.adoc[SAMM CLI]
22
* xref:java-aspect-tooling.adoc[Java APIs for Aspect Models]
33
* xref:maven-plugin.adoc[Maven Plugin]
4+
* xref:error-codes.adoc[Error Codes and Validation Results]
45
* xref:bamm-migration.adoc[Migration from BAMM]

0 commit comments

Comments
 (0)