Skip to content

Commit

Permalink
Add warnings for errors while parsing a SnowflakeConnectString (#1166)
Browse files Browse the repository at this point in the history
code changes is only for log entries. Test failures expected from external fork. No need to run it as such for this PR.
  • Loading branch information
ash211 authored Nov 2, 2022
1 parent 2b6ab7e commit c653e17
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ public class SnowflakeConnectString implements Serializable {

public static SnowflakeConnectString parse(String url, Properties info) {
if (url == null) {
logger.warn("Connect strings must be non-null");
return INVALID_CONNECT_STRING;
}
int pos = url.indexOf(PREFIX);
if (pos != 0) {
logger.warn("Connect strings must start with jdbc:snowflake://");
return INVALID_CONNECT_STRING; // not start with jdbc:snowflake://
}
String afterPrefix = url.substring(pos + PREFIX.length());
Expand Down Expand Up @@ -62,16 +64,19 @@ public static SnowflakeConnectString parse(String url, Properties info) {
String queryData = uri.getRawQuery();

if (!scheme.equals("snowflake") && !scheme.equals("http") && !scheme.equals("https")) {
logger.warn("Connect strings must have a valid scheme: 'snowflake' or 'http' or 'https'");
return INVALID_CONNECT_STRING;
}
if (Strings.isNullOrEmpty(host)) {
logger.warn("Connect strings must have a valid host: found null or empty host");
return INVALID_CONNECT_STRING;
}
if (port == -1) {
port = 443;
}
String path = uri.getPath();
if (!Strings.isNullOrEmpty(path) && !"/".equals(path)) {
logger.warn("Connect strings must have no path: expecting empty or null or '/'");
return INVALID_CONNECT_STRING;
}
String account = null;
Expand Down Expand Up @@ -147,6 +152,7 @@ public static SnowflakeConnectString parse(String url, Properties info) {

return new SnowflakeConnectString(scheme, host, port, parameters, account);
} catch (Exception ex) {
logger.warn("Exception thrown while parsing Snowflake connect string", ex);
return INVALID_CONNECT_STRING;
}
}
Expand Down

0 comments on commit c653e17

Please sign in to comment.