Skip to content

Commit d249da1

Browse files
author
dpolishc
committed
Too big error message #4827
1 parent 751c5b5 commit d249da1

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/main/java/org/jabref/logic/shared/DBMSConnection.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package org.jabref.logic.shared;
22

3-
import java.sql.Connection;
4-
import java.sql.DriverManager;
5-
import java.sql.SQLException;
6-
import java.util.HashSet;
7-
import java.util.Set;
8-
93
import org.jabref.logic.l10n.Localization;
104
import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException;
115
import org.jabref.model.database.shared.DBMSType;
126
import org.jabref.model.database.shared.DatabaseConnection;
13-
147
import org.slf4j.Logger;
158
import org.slf4j.LoggerFactory;
169

10+
import java.sql.Connection;
11+
import java.sql.DriverManager;
12+
import java.sql.SQLException;
13+
import java.util.HashSet;
14+
import java.util.Set;
15+
1716
public class DBMSConnection implements DatabaseConnection {
1817

1918
private static final Logger LOGGER = LoggerFactory.getLogger(DBMSConnection.class);
@@ -38,9 +37,12 @@ public DBMSConnection(DBMSConnectionProperties connectionProperties) throws SQLE
3837
} catch (SQLException e) {
3938
// Some systems like PostgreSQL retrieves 0 to every exception.
4039
// Therefore a stable error determination is not possible.
41-
LOGGER.error("Could not connect to database: " + e.getMessage() + " - Error code: " + e.getErrorCode());
40+
String message = e.getMessage();
41+
int endIndex = message.indexOf(".") != -1 ? message.indexOf(".") : message.length();
42+
String errorMessagee = e.getSQLState().equals("01S00") ? message.substring(0, endIndex) : message;
43+
LOGGER.error("Could not connect to database: " + message + " - Error code: " + e.getErrorCode());
4244

43-
throw e;
45+
throw new SQLException(errorMessagee, e);
4446
}
4547
}
4648

0 commit comments

Comments
 (0)