Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2714: loggingOfErrors #2870

Merged
merged 6 commits into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions eo-maven-plugin/src/main/java/org/eolang/maven/VerifyMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.eolang.maven;

import com.jcabi.log.Logger;
import com.jcabi.xml.XML;
import com.yegor256.xsline.TrClasspath;
import com.yegor256.xsline.TrDefault;
import java.nio.file.Path;
Expand Down Expand Up @@ -105,6 +106,7 @@ void exec() {
*/
private Optimization optimization() {
Optimization opt = new OptTrain(
this::logErrors,
new TrClasspath<>(
new TrDefault<>(),
"/org/eolang/parser/fail-on-errors.xsl",
Expand All @@ -117,4 +119,35 @@ private Optimization optimization() {
return opt;
}

/**
* Log errors of xml.
* @param xml XMIR.
* @return XML.
*/
private XML logErrors(final XML xml) {
for (final XML error: xml.nodes("/program/errors/error")) {
final String message = Logger.format(
"%[file]s, line %s: %s",
xml.xpath("/program/@source").get(0),
error.xpath("@line").get(0),
error.xpath("text()").get(0)
);
final String severity = error.xpath("@severity").get(0);
switch (severity) {
case "warning":
Logger.warn(this, message);
break;
case "error":
case "critical":
Logger.error(this, message);
break;
default:
throw new IllegalArgumentException(
String.format("Incorrect severity: %s", severity)
);
}
}
return xml;
}

}
Loading