{"record":{"id":"da626221b838f2b7","repo":"puppetlabs/puppet","slug":"data-must-be-a-string-not-class-name","errorCode":null,"errorMessage":"data must be a string, not %{class_name}","messagePattern":"data must be a string, not %(.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/windows/eventlog.rb","lineNumber":62,"sourceCode":"  def close\n    DeregisterEventSource(@eventlog_handle)\n  ensure\n    @eventlog_handle = nil\n  end\n\n  # Report an event to this instance's event log handle. Accepts a string to\n  #   report (:data => <string>) and event type (:event_type => Integer) and id\n  # (:event_id => Integer) as returned by #to_native. The additional arguments to\n  # ReportEventW seen in this method aren't exposed - though ReportEventW\n  # technically can accept multiple strings as well as raw binary data to log,\n  # we accept a single string from Puppet::Util::Log\n  #\n  # @param args [Hash{Symbol=>Object}] options to the associated log event\n  # @return [void]\n  # @api public\n  def report_event(args = {})\n    unless args[:data].is_a?(String)\n      raise ArgumentError, _(\"data must be a string, not %{class_name}\") % { class_name: args[:data].class }\n    end\n\n    from_string_to_wide_string(args[:data]) do |message_ptr|\n      FFI::MemoryPointer.new(:pointer) do |message_array_ptr|\n        message_array_ptr.write_pointer(message_ptr)\n        user_sid = FFI::Pointer::NULL\n        raw_data = FFI::Pointer::NULL\n        raw_data_size = 0\n        num_strings = 1\n        eventlog_category = 0\n        report_result = ReportEventW(@eventlog_handle, args[:event_type],\n                                     eventlog_category, args[:event_id], user_sid,\n                                     num_strings, raw_data_size, message_array_ptr, raw_data)\n\n        if report_result == WIN32_FALSE\n          # TRANSLATORS 'Windows' is the operating system and 'ReportEventW' is a API call and should not be translated\n          raise EventLogError.new(_(\"ReportEventW failed to report event to Windows eventlog\"), FFI.errno)\n        end","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/windows/eventlog.rb#L44-L80","documentation":"ArgumentError from Puppet::Util::Windows::EventLog#report_event: the :data option must be a String because this wrapper logs exactly one wide string via ReportEventW (num_strings is hard-coded to 1, raw data is NULL). No to_s coercion happens, so nil, Integer, or structured objects are rejected before the FFI call.","triggerScenarios":"report_event(data: nil), report_event(data: 42), or forwarding a Puppet::Util::Log / hash object as :data — i.e. any caller assuming automatic string conversion.","commonSituations":"Custom Windows eventlog forwarding hooked into Puppet::Util::Log where the payload is structured; refactors that change what feeds :data from pre-formatted strings to objects.","solutions":["Coerce explicitly: report_event(data: message.to_s).","Fix the upstream pipeline so whatever produces :data guarantees a String.","Add a spec asserting the data type at the boundary."],"exampleFix":"# before\neventlog.report_event(data: log_entry, event_type: 0x0001, event_id: 1) # log_entry not a String\n\n# after\neventlog.report_event(data: log_entry.to_s, event_type: 0x0001, event_id: 1)","handlingStrategy":"type-guard","validationCode":"args[:data] = args[:data].to_s unless args[:data].is_a?(String)\neventlog.report_event(args)","typeGuard":"def string_event_data?(args)\n  args[:data].is_a?(String)\nend","tryCatchPattern":"begin\n  @eventlog.report_event(args)\nrescue ArgumentError => e\n  warn \"dropping non-string event data (#{e.message})\"\nend","preventionTips":["Coerce with to_s at the logging boundary.","Type-check structured payloads before forwarding to the Windows event log.","Unit-test log sinks with nil and non-string inputs."],"tags":["puppet","windows","eventlog","type-validation","logging"],"backgroundTag":"wrong-argument-type","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}