{"record":{"id":"1b159d1b8199ff36","repo":"puppetlabs/puppet","slug":"invalid-log-level-level","errorCode":null,"errorMessage":"Invalid log level %{level}","messagePattern":"Invalid log level %(.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/windows/eventlog.rb","lineNumber":102,"sourceCode":"\n  class << self\n    # Feels more natural to do Puppet::Util::Window::EventLog.open(\"MyApplication\")\n    alias :open :new\n\n    # Query event identifier info for a given log level\n    # @param level [Symbol] an event log level\n    # @return [Array] Win API Event ID, Puppet Event ID\n    # @api public\n    def to_native(level)\n      case level\n      when :debug, :info, :notice\n        [EVENTLOG_INFORMATION_TYPE, 0x01]\n      when :warning\n        [EVENTLOG_WARNING_TYPE, 0x02]\n      when :err, :alert, :emerg, :crit\n        [EVENTLOG_ERROR_TYPE, 0x03]\n      else\n        raise ArgumentError, _(\"Invalid log level %{level}\") % { level: level }\n      end\n    end\n  end\n\n  private\n\n  # For the purposes of allowing this class to be standalone, the following are\n  # duplicate definitions from elsewhere in Puppet:\n\n  # If we're loaded via Puppet we should keep the previous behavior of raising\n  # Puppet::Util::Windows::Error on errors. If we aren't, at least concatenate\n  # the error code to the exception message to pass this information on to the\n  # user\n  if defined?(Puppet::Util::Windows::Error)\n    EventLogError = Puppet::Util::Windows::Error\n  else\n    class EventLogError < RuntimeError\n      def initialize(msg, code)","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/windows/eventlog.rb#L84-L120","documentation":"Puppet::Util::Windows::Eventlog.to_native maps a Puppet log level symbol to a [Windows event type, event ID] pair so Puppet messages can be written to the Windows Event Log. It accepts exactly eight levels (:debug, :info, :notice, :warning, :err, :alert, :emerg, :crit); anything else raises ArgumentError. The raise is a pure input-validation failure, not a Windows API failure.","triggerScenarios":"Calling to_native with a String ('warning' instead of :warning), nil, or a level outside the eight supported symbols, e.g. a custom log level like :verbose or :audit registered by a module or sent by puppetserver. It also fires when forwarding log levels read from YAML/JSON config verbatim without symbolizing.","commonSituations":"Custom log levels added by site modules or newer Puppet versions that this helper was never taught; log levels arriving as strings over HTTP/report handlers; test fixtures passing capitalized level names (:Warning, :ERROR).","solutions":["Pass one of the eight supported symbols: :debug, :info, :notice, :warning, :err, :alert, :emerg, :crit","Symbolize strings from config before calling: level.to_sym","Map custom/unknown levels to the nearest supported one (e.g. :verbose -> :debug, :fatal -> :emerg)","Rescue ArgumentError at the call site and downgrade to :notice as a safe default"],"exampleFix":"// before\nPuppet::Util::Windows::Eventlog.to_native('warning')   # String -> ArgumentError\nPuppet::Util::Windows::Eventlog.to_native(:verbose)     # custom level -> ArgumentError\n\n// after\nlevel = level.to_sym if level.is_a?(String)\nnative = Puppet::Util::Windows::Eventlog.to_native(level) rescue Puppet::Util::Windows::Eventlog.to_native(:notice)","handlingStrategy":"validation","validationCode":"VALID_EVENTLOG_LEVELS = %i[debug info notice warning err alert emerg crit].freeze\nlevel = level.to_sym if level.is_a?(String)\nraise ArgumentError, \"unsupported log level #{level}\" unless VALID_EVENTLOG_LEVELS.include?(level)\nnative = Puppet::Util::Windows::Eventlog.to_native(level)","typeGuard":"def eventlog_level?(value)\n  normalized = value.is_a?(String) ? value.to_sym : value\n  %i[debug info notice warning err alert emerg crit].include?(normalized)\nend","tryCatchPattern":"begin\n  event_type, event_id = Puppet::Util::Windows::Eventlog.to_native(level)\nrescue ArgumentError\n  event_type, event_id = Puppet::Util::Windows::Eventlog.to_native(:notice)\nend","preventionTips":["Symbolize levels coming from config files with to_sym before use","Map custom levels to the nearest of the eight supported Puppet levels at your logging boundary","Rescue ArgumentError and downgrade to :notice rather than dropping the message"],"tags":["windows","eventlog","log-level","argumenterror","puppet"],"backgroundTag":"invalid-log-level","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}