Skip to content

Commit

Permalink
🖊️ Attach SimpleLogger to @logger when invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
oakbani committed Jun 20, 2018
1 parent f08fb1d commit 0e2e885
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions lib/optimizely.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,24 @@ def initialize(datafile, event_dispatcher = nil, logger = nil, error_handler = n
validate_instantiation_options(datafile, skip_json_validation)
rescue InvalidInputError => e
@is_valid = false
logger = SimpleLogger.new
logger.log(Logger::ERROR, e.message)
@logger = SimpleLogger.new
@logger.log(Logger::ERROR, e.message)
return
end

begin
@config = ProjectConfig.new(datafile, @logger, @error_handler)
rescue
@is_valid = false
logger = SimpleLogger.new
logger.log(Logger::ERROR, InvalidInputError.new('datafile').message)
@logger = SimpleLogger.new
@logger.log(Logger::ERROR, InvalidInputError.new('datafile').message)
return
end

unless @config.parsing_succeeded?
@is_valid = false
logger = SimpleLogger.new
logger.log(Logger::ERROR, InvalidDatafileVersionError.new.message)
@logger = SimpleLogger.new
@logger.log(Logger::ERROR, InvalidDatafileVersionError.new.message)
return
end

Expand All @@ -100,8 +100,7 @@ def activate(experiment_key, user_id, attributes = nil)
# Returns nil if experiment is not Running, if user is not in experiment, or if datafile is invalid.

unless @is_valid
logger = SimpleLogger.new
logger.log(Logger::ERROR, InvalidDatafileError.new('activate').message)
@logger.log(Logger::ERROR, InvalidDatafileError.new('activate').message)
return nil
end

Expand Down Expand Up @@ -137,8 +136,7 @@ def get_variation(experiment_key, user_id, attributes = nil)
# Returns nil if experiment is not Running, if user is not in experiment, or if datafile is invalid.

unless @is_valid
logger = SimpleLogger.new
logger.log(Logger::ERROR, InvalidDatafileError.new('get_variation').message)
@logger.log(Logger::ERROR, InvalidDatafileError.new('get_variation').message)
return nil
end

Expand Down Expand Up @@ -200,8 +198,7 @@ def track(event_key, user_id, attributes = nil, event_tags = nil)
# event_tags - Hash representing metadata associated with the event.

unless @is_valid
logger = SimpleLogger.new
logger.log(Logger::ERROR, InvalidDatafileError.new('track').message)
@logger.log(Logger::ERROR, InvalidDatafileError.new('track').message)
return nil
end

Expand Down Expand Up @@ -259,8 +256,7 @@ def is_feature_enabled(feature_flag_key, user_id, attributes = nil)
# False if the feature is disabled.
# False if the feature is not found.
unless @is_valid
logger = SimpleLogger.new
logger.log(Logger::ERROR, InvalidDatafileError.new('is_feature_enabled').message)
@logger.log(Logger::ERROR, InvalidDatafileError.new('is_feature_enabled').message)
return false
end

Expand Down Expand Up @@ -315,8 +311,7 @@ def get_enabled_features(user_id, attributes = nil)
enabled_features = []

unless @is_valid
logger = SimpleLogger.new
logger.log(Logger::ERROR, InvalidDatafileError.new('get_enabled_features').message)
@logger.log(Logger::ERROR, InvalidDatafileError.new('get_enabled_features').message)
return enabled_features
end

Expand Down Expand Up @@ -344,8 +339,7 @@ def get_feature_variable_string(feature_flag_key, variable_key, user_id, attribu
# Returns nil if the feature flag or variable are not found.

unless @is_valid
logger = SimpleLogger.new
logger.log(Logger::ERROR, InvalidDatafileError.new('get_feature_variable_string').message)
@logger.log(Logger::ERROR, InvalidDatafileError.new('get_feature_variable_string').message)
return nil
end

Expand All @@ -372,8 +366,7 @@ def get_feature_variable_boolean(feature_flag_key, variable_key, user_id, attrib
# Returns nil if the feature flag or variable are not found.

unless @is_valid
logger = SimpleLogger.new
logger.log(Logger::ERROR, InvalidDatafileError.new('get_feature_variable_boolean').message)
@logger.log(Logger::ERROR, InvalidDatafileError.new('get_feature_variable_boolean').message)
return nil
end

Expand All @@ -400,8 +393,7 @@ def get_feature_variable_double(feature_flag_key, variable_key, user_id, attribu
# Returns nil if the feature flag or variable are not found.

unless @is_valid
logger = SimpleLogger.new
logger.log(Logger::ERROR, InvalidDatafileError.new('get_feature_variable_double').message)
@logger.log(Logger::ERROR, InvalidDatafileError.new('get_feature_variable_double').message)
return nil
end

Expand All @@ -428,8 +420,7 @@ def get_feature_variable_integer(feature_flag_key, variable_key, user_id, attrib
# Returns nil if the feature flag or variable are not found.

unless @is_valid
logger = SimpleLogger.new
logger.log(Logger::ERROR, InvalidDatafileError.new('get_feature_variable_integer').message)
@logger.log(Logger::ERROR, InvalidDatafileError.new('get_feature_variable_integer').message)
return nil
end

Expand Down

0 comments on commit 0e2e885

Please sign in to comment.