daemon-kit icon indicating copy to clipboard operation
daemon-kit copied to clipboard

Unexpected config loading behaviour

Open kennethkalmer opened this issue 10 years ago • 1 comments

Just helped @ranaldobowker debug an issue where a config file loaded by DaemonKit::Config was missing the correct environment name in the top-level of the YAML file, and subsequently blew up badly.

The offending lines in DaemonKit::Config#initialize tests for the presence of the DAEMON_ENV in the hash, and pulls that up one level.

Although this was probably amazing at the time, I think this magic is no longer good practice... We need to figure out how we can improve this and safeguard users from pulling out their hair...

@marcbowes any ideas?

kennethkalmer avatar Jan 30 '15 21:01 kennethkalmer

My recommendation is to not have 2 ways (either by-env or top-level) ways of doing it, plus clear guidance when the user gets it wrong, rather than making them read/understand a stacktrace.

def initialize( config_data ) #:nodoc:
  if config_data.has_key?( DAEMON_ENV )
    self.data = config_data[ DAEMON_ENV ]
  else
    raise ArgumentError, "Invalid config (missing key #{DAEMON_ENV.inspect}); " +
      "please refer to user guide / wiki for further details"
  end
end

marcbowes avatar Feb 12 '15 13:02 marcbowes