[#7171] Better exception formatting (adding ... around abbreviated SQL strings)
This commit is contained in:
parent
feb2f43785
commit
57b98bcf70
@ -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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user