Skip to content

Commit

Permalink
Raise clearer errors when configs are Missing
Browse files Browse the repository at this point in the history
e.g. currently if SNOWFLAKE_PRIVATE_KEY and SNOWFLAKE_PRIVATE_KEY_PATH
are not set, the error message is:
  TypeError: no implicit conversion of nil into String
  • Loading branch information
jordan-brough committed Jul 26, 2024
1 parent 9ba8b75 commit 6ee4bed
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/ruby_snowflake/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def initialize(details)
class BadResponseError < Error ; end
class ConnectionError < Error ; end
class ConnectionStarvedError < Error ; end
class MissingConfig < Error ; end
class RetryableBadResponseError < Error ; end
class RequestError < Error ; end
class QueryTimeoutError < Error ; end
Expand Down Expand Up @@ -73,14 +74,21 @@ def self.from_env(logger: DEFAULT_LOGGER,
thread_scale_factor: env_option("SNOWFLAKE_THREAD_SCALE_FACTOR", DEFAULT_THREAD_SCALE_FACTOR),
http_retries: env_option("SNOWFLAKE_HTTP_RETRIES", DEFAULT_HTTP_RETRIES),
query_timeout: env_option("SNOWFLAKE_QUERY_TIMEOUT", DEFAULT_QUERY_TIMEOUT))
private_key = ENV["SNOWFLAKE_PRIVATE_KEY"] || File.read(ENV["SNOWFLAKE_PRIVATE_KEY_PATH"])
private_key =
if key = ENV["SNOWFLAKE_PRIVATE_KEY"]
key
elsif path = ENV["SNOWFLAKE_PRIVATE_KEY_PATH"]
File.read(path)
else
raise MissingConfig.new({}), "Either ENV['SNOWFLAKE_PRIVATE_KEY'] or ENV['SNOWFLAKE_PRIVATE_KEY_PATH'] must be set"
end

new(
ENV["SNOWFLAKE_URI"],
ENV.fetch("SNOWFLAKE_URI"),
private_key,
ENV["SNOWFLAKE_ORGANIZATION"],
ENV["SNOWFLAKE_ACCOUNT"],
ENV["SNOWFLAKE_USER"],
ENV.fetch("SNOWFLAKE_ORGANIZATION"),
ENV.fetch("SNOWFLAKE_ACCOUNT"),
ENV.fetch("SNOWFLAKE_USER"),
ENV["SNOWFLAKE_DEFAULT_WAREHOUSE"],
ENV["SNOWFLAKE_DEFAULT_DATABASE"],
logger: logger,
Expand Down

0 comments on commit 6ee4bed

Please sign in to comment.