Skip to content

Commit 19db9b3

Browse files
SNOW-1880134: Improve exception message when getting query metadata (#2059)
1 parent 236e4ed commit 19db9b3

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/main/java/net/snowflake/client/core/SFSession.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ private JsonNode getQueryMetadata(String queryID) throws SQLException {
241241
queryID,
242242
this,
243243
e.getMessage(),
244-
"No response or invalid response from GET request. Error: {}");
244+
"No response or invalid response from GET request. Error: " + e.getMessage(),
245+
e);
245246
}
246247

247248
// Get response as JSON and parse it to get the query status

src/main/java/net/snowflake/client/jdbc/SnowflakeSQLLoggedException.java

+14-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import net.snowflake.client.core.ObjectMapperFactory;
2121
import net.snowflake.client.core.SFBaseSession;
2222
import net.snowflake.client.core.SFException;
23+
import net.snowflake.client.core.SFSession;
2324
import net.snowflake.client.jdbc.telemetry.Telemetry;
2425
import net.snowflake.client.jdbc.telemetry.TelemetryField;
2526
import net.snowflake.client.jdbc.telemetry.TelemetryUtil;
@@ -41,6 +42,13 @@ public class SnowflakeSQLLoggedException extends SnowflakeSQLException {
4142
private static final SFLogger logger =
4243
SFLoggerFactory.getLogger(SnowflakeSQLLoggedException.class);
4344
private static final ObjectMapper mapper = ObjectMapperFactory.getObjectMapper();
45+
private static final int NO_VENDOR_CODE = -1;
46+
47+
public SnowflakeSQLLoggedException(
48+
String queryID, SFSession session, String sqlState, String message, Exception cause) {
49+
super(queryID, cause, sqlState, NO_VENDOR_CODE, message);
50+
sendTelemetryData(queryID, sqlState, NO_VENDOR_CODE, session, this);
51+
}
4452

4553
/**
4654
* Function to create a TelemetryEvent log from the JSONObject and exception and send it via OOB
@@ -134,7 +142,7 @@ static JSONObject createOOBValue(String queryId, String SQLState, int vendorCode
134142
if (!Strings.isNullOrEmpty(SQLState)) {
135143
oobValue.put("SQLState", SQLState);
136144
}
137-
if (vendorCode != -1) {
145+
if (vendorCode != NO_VENDOR_CODE) {
138146
oobValue.put("ErrorNumber", vendorCode);
139147
}
140148
return oobValue;
@@ -159,7 +167,7 @@ static ObjectNode createIBValue(String queryId, String SQLState, int vendorCode)
159167
if (!Strings.isNullOrEmpty(SQLState)) {
160168
ibValue.put("SQLState", SQLState);
161169
}
162-
if (vendorCode != -1) {
170+
if (vendorCode != NO_VENDOR_CODE) {
163171
ibValue.put("ErrorNumber", vendorCode);
164172
}
165173
return ibValue;
@@ -281,7 +289,7 @@ public SnowflakeSQLLoggedException(SFBaseSession session, String SQLState, Strin
281289
public SnowflakeSQLLoggedException(
282290
String queryId, SFBaseSession session, String SQLState, String reason) {
283291
super(reason, SQLState);
284-
sendTelemetryData(queryId, SQLState, -1, session, this);
292+
sendTelemetryData(queryId, SQLState, NO_VENDOR_CODE, session, this);
285293
}
286294

287295
/**
@@ -374,7 +382,7 @@ public SnowflakeSQLLoggedException(SFBaseSession session, ErrorCode errorCode, O
374382
public SnowflakeSQLLoggedException(
375383
String queryId, SFBaseSession session, ErrorCode errorCode, Object... params) {
376384
super(queryId, errorCode, params);
377-
sendTelemetryData(queryId, null, -1, session, this);
385+
sendTelemetryData(queryId, null, NO_VENDOR_CODE, session, this);
378386
}
379387

380388
/**
@@ -383,7 +391,7 @@ public SnowflakeSQLLoggedException(
383391
*/
384392
public SnowflakeSQLLoggedException(SFBaseSession session, SFException e) {
385393
super(e);
386-
sendTelemetryData(null, null, -1, session, this);
394+
sendTelemetryData(null, null, NO_VENDOR_CODE, session, this);
387395
}
388396

389397
/**
@@ -405,6 +413,6 @@ public SnowflakeSQLLoggedException(SFBaseSession session, String reason) {
405413
*/
406414
public SnowflakeSQLLoggedException(String queryId, SFBaseSession session, String reason) {
407415
super(queryId, reason, null);
408-
sendTelemetryData(queryId, null, -1, session, this);
416+
sendTelemetryData(queryId, null, NO_VENDOR_CODE, session, this);
409417
}
410418
}

0 commit comments

Comments
 (0)