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

Improve logging for query parse error in ApplyConstructModule #241

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 14 additions & 1 deletion s-pipes-core/src/main/java/cz/cvut/spipes/util/QueryUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cz.cvut.spipes.util;


import org.apache.commons.lang3.StringUtils;
import org.apache.jena.query.*;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.RDFNode;
Expand All @@ -12,6 +13,7 @@
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class QueryUtils {
Expand Down Expand Up @@ -183,7 +185,18 @@ public static Query createQuery(org.topbraid.spin.model.Query spinQuery) {
return ARQFactory.get().createQuery(spinQuery);
} catch (QueryParseException e) {
String query = ARQFactory.get().createCommandString(spinQuery);
LOG.error("Parse error [1] occurred in query [2].\n[1] ERROR:\n{}\n[2] QUERY:\n{}", e.getMessage(), query);
String msg = e.getMessage();
Pattern pattern = Pattern.compile("line\\s+(\\d+)");
Matcher matcher = pattern.matcher(msg);
matcher.find();
String numberAfterLine = matcher.group(1);
int wrongLineNumber = Integer.valueOf(numberAfterLine); //e.g
// etLine() returns wrong number for some reason
int beginningOfTheWrongLine = StringUtils.ordinalIndexOf(query, "\n", wrongLineNumber - 1);
int endOfTheWrongLine = StringUtils.ordinalIndexOf(query, "\n", wrongLineNumber);
String wrongLine = query.substring(beginningOfTheWrongLine, endOfTheWrongLine);
LOG.error("Parse error [1] occurred in lines [2].\n[1] ERROR:\n{}\n[2] LINE:\n{}",
msg, wrongLine);
throw e;
}
}
Expand Down
Loading