[#7171] Better exception formatting (adding ... around abbreviated SQL strings)

This commit is contained in:
lukaseder 2018-03-09 09:51:50 +01:00
parent feb2f43785
commit 57b98bcf70
2 changed files with 12 additions and 5 deletions

View File

@ -37,8 +37,6 @@
*/
package org.jooq.impl;
import static org.jooq.exception.SQLStateSubclass.C42000_NO_SUBCLASS;
import org.jooq.DSLContext;
import org.jooq.exception.DataAccessException;
import org.jooq.exception.SQLStateSubclass;
@ -65,7 +63,7 @@ public final class ParserException extends DataAccessException {
}
public ParserException(String sql, String message) {
this(sql, message, C42000_NO_SUBCLASS);
this(sql, message, null);
}
public ParserException(String sql, String message, SQLStateSubclass state) {
@ -73,7 +71,11 @@ public final class ParserException extends DataAccessException {
}
public ParserException(String sql, String message, SQLStateSubclass state, Throwable cause) {
super(state + ": " + (message == null ? "" : message + ": ") + sql, cause);
super(
(state == null ? "" : state + ": ")
+ (message == null ? "" : message + ": ")
+ sql, cause
);
this.sql = sql;
}

View File

@ -7338,7 +7338,12 @@ final class ParserImpl implements Parser {
String mark() {
int[] line = line();
return "[" + line[0] + ":" + line[1] + "] " + sqlString.substring(Math.max(0, position - 50), position) + "[*]" + sqlString.substring(position, Math.min(sqlString.length(), position + 80));
return "[" + line[0] + ":" + line[1] + "] "
+ (position > 50 ? "..." : "")
+ sqlString.substring(Math.max(0, position - 50), position)
+ "[*]"
+ sqlString.substring(position, Math.min(sqlString.length(), position + 80))
+ (sqlString.length() > position + 80 ? "..." : "");
}
@Override