Skip to content

Commit

Permalink
[#7171] Better exception formatting (adding ... around abbreviated SQ…
Browse files Browse the repository at this point in the history
…L strings)
  • Loading branch information
lukaseder committed Mar 9, 2018
1 parent feb2f43 commit 57b98bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 6 additions & 4 deletions jOOQ/src/main/java/org/jooq/impl/ParserException.java
Expand Up @@ -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;
Expand All @@ -65,15 +63,19 @@ public ParserException(String sql) {
}

public ParserException(String sql, String message) {
this(sql, message, C42000_NO_SUBCLASS);
this(sql, message, null);
}

public ParserException(String sql, String message, SQLStateSubclass state) {
this(sql, message, state, null);
}

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;
}
Expand Down
7 changes: 6 additions & 1 deletion jOOQ/src/main/java/org/jooq/impl/ParserImpl.java
Expand Up @@ -7338,7 +7338,12 @@ boolean done(String message) {

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
Expand Down

0 comments on commit 57b98bc

Please sign in to comment.