Skip to content

Commit

Permalink
SNOW-1880134: Improve exception message when getting query metadata (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dprzybysz authored Jan 31, 2025
1 parent 236e4ed commit 19db9b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/main/java/net/snowflake/client/core/SFSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ private JsonNode getQueryMetadata(String queryID) throws SQLException {
queryID,
this,
e.getMessage(),
"No response or invalid response from GET request. Error: {}");
"No response or invalid response from GET request. Error: " + e.getMessage(),
e);
}

// Get response as JSON and parse it to get the query status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.snowflake.client.core.ObjectMapperFactory;
import net.snowflake.client.core.SFBaseSession;
import net.snowflake.client.core.SFException;
import net.snowflake.client.core.SFSession;
import net.snowflake.client.jdbc.telemetry.Telemetry;
import net.snowflake.client.jdbc.telemetry.TelemetryField;
import net.snowflake.client.jdbc.telemetry.TelemetryUtil;
Expand All @@ -41,6 +42,13 @@ public class SnowflakeSQLLoggedException extends SnowflakeSQLException {
private static final SFLogger logger =
SFLoggerFactory.getLogger(SnowflakeSQLLoggedException.class);
private static final ObjectMapper mapper = ObjectMapperFactory.getObjectMapper();
private static final int NO_VENDOR_CODE = -1;

public SnowflakeSQLLoggedException(
String queryID, SFSession session, String sqlState, String message, Exception cause) {
super(queryID, cause, sqlState, NO_VENDOR_CODE, message);
sendTelemetryData(queryID, sqlState, NO_VENDOR_CODE, session, this);
}

/**
* Function to create a TelemetryEvent log from the JSONObject and exception and send it via OOB
Expand Down Expand Up @@ -134,7 +142,7 @@ static JSONObject createOOBValue(String queryId, String SQLState, int vendorCode
if (!Strings.isNullOrEmpty(SQLState)) {
oobValue.put("SQLState", SQLState);
}
if (vendorCode != -1) {
if (vendorCode != NO_VENDOR_CODE) {
oobValue.put("ErrorNumber", vendorCode);
}
return oobValue;
Expand All @@ -159,7 +167,7 @@ static ObjectNode createIBValue(String queryId, String SQLState, int vendorCode)
if (!Strings.isNullOrEmpty(SQLState)) {
ibValue.put("SQLState", SQLState);
}
if (vendorCode != -1) {
if (vendorCode != NO_VENDOR_CODE) {
ibValue.put("ErrorNumber", vendorCode);
}
return ibValue;
Expand Down Expand Up @@ -281,7 +289,7 @@ public SnowflakeSQLLoggedException(SFBaseSession session, String SQLState, Strin
public SnowflakeSQLLoggedException(
String queryId, SFBaseSession session, String SQLState, String reason) {
super(reason, SQLState);
sendTelemetryData(queryId, SQLState, -1, session, this);
sendTelemetryData(queryId, SQLState, NO_VENDOR_CODE, session, this);
}

/**
Expand Down Expand Up @@ -374,7 +382,7 @@ public SnowflakeSQLLoggedException(SFBaseSession session, ErrorCode errorCode, O
public SnowflakeSQLLoggedException(
String queryId, SFBaseSession session, ErrorCode errorCode, Object... params) {
super(queryId, errorCode, params);
sendTelemetryData(queryId, null, -1, session, this);
sendTelemetryData(queryId, null, NO_VENDOR_CODE, session, this);
}

/**
Expand All @@ -383,7 +391,7 @@ public SnowflakeSQLLoggedException(
*/
public SnowflakeSQLLoggedException(SFBaseSession session, SFException e) {
super(e);
sendTelemetryData(null, null, -1, session, this);
sendTelemetryData(null, null, NO_VENDOR_CODE, session, this);
}

/**
Expand All @@ -405,6 +413,6 @@ public SnowflakeSQLLoggedException(SFBaseSession session, String reason) {
*/
public SnowflakeSQLLoggedException(String queryId, SFBaseSession session, String reason) {
super(queryId, reason, null);
sendTelemetryData(queryId, null, -1, session, this);
sendTelemetryData(queryId, null, NO_VENDOR_CODE, session, this);
}
}

0 comments on commit 19db9b3

Please sign in to comment.