module Honeybadger::Config::Yaml
def self.load_yaml(path)
def self.load_yaml(path) begin # This uses `YAML.unsafe_load` to support loading arbitrary Ruby # classes, such as !ruby/regexp. This was the default behavior prior # to Psych 4. https://bugs.ruby-lang.org/issues/17866 method = YAML.respond_to?(:unsafe_load) ? :unsafe_load : :load yaml = YAML.send(method, ERB.new(path.read).result) rescue => e config_error = ConfigError.new(e.to_s) if e.backtrace backtrace = e.backtrace.map do |line| if line.start_with?('(erb)'.freeze) line.gsub('(erb)'.freeze, path.to_s) else line end end config_error.set_backtrace(backtrace) end raise config_error end case yaml when Hash yaml when NilClass, FalseClass {} else raise ConfigError, "The configuration file #{path} is invalid." end end