{"record":{"id":"71b6a248cf3812ee","repo":"fluent/fluentd","slug":"value-must-be-a-string-or-a-number-value-val","errorCode":null,"errorMessage":"value must be a string or a number: #{value}(#{value.class})","messagePattern":"value must be a string or a number: #(.+?)\\(#(.+?)\\)","errorType":"exception","errorClass":"Fluent::TimeParser::TimeParseError","httpStatus":null,"severity":"error","filePath":"lib/fluent/time.rb","lineNumber":308,"sourceCode":"    alias :call :parse\n  end\n\n  class NumericTimeParser < TimeParser # to include TimeParseError\n    def initialize(type, localtime = nil, timezone = nil)\n      @cache1_key = @cache1_time = @cache2_key = @cache2_time = nil\n\n      if type == :unixtime\n        define_singleton_method(:parse, method(:parse_unixtime))\n        define_singleton_method(:call, method(:parse_unixtime))\n      else # :float\n        define_singleton_method(:parse, method(:parse_float))\n        define_singleton_method(:call, method(:parse_float))\n      end\n    end\n\n    def parse_unixtime(value)\n      unless value.is_a?(String) || value.is_a?(Numeric)\n        raise TimeParseError, \"value must be a string or a number: #{value}(#{value.class})\"\n      end\n\n      if @cache1_key == value\n        return @cache1_time\n      elsif @cache2_key == value\n        return @cache2_time\n      end\n\n      begin\n        time = Fluent::EventTime.new(value.to_i)\n      rescue => e\n        raise TimeParseError, \"invalid time format: value = #{value}, error_class = #{e.class.name}, error = #{e.message}\"\n      end\n      @cache1_key = @cache2_key\n      @cache1_time = @cache2_time\n      @cache2_key = value\n      @cache2_time = time\n      time","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/fluent/fluentd/blob/dd45c6e18dc7be33b5e5a0f0767bf46307ff5626/lib/fluent/time.rb#L290-L326","documentation":"Fluent::TimeParseError raised by NumericTimeParser#parse_unixtime (lib/fluent/time.rb:308) when the value is neither a String nor a Numeric — for example a Hash, Array, true/false, or nil. This is the type-gate in front of epoch-seconds parsing; valid Strings are then coerced with to_i, so unparseable-but-numeric-looking strings do not raise here.","triggerScenarios":"time_type unixtime configured and a record's time field is a JSON object/array/boolean/null (e.g. {\"time\": null} or {\"time\": {\"$date\": ...}}); calling parser.parse(nil) or parser.parse({}) on a NumericTimeParser built for :unixtime.","commonSituations":"MongoDB-style extended JSON dates ($date wrapper) arriving as a Hash; producer omits the time field making it nil; a filter replaces the time field with a structured value; API changes turning the field into a nested object.","solutions":["Validate the field exists and is String/Numeric before it reaches the parser (record_filter or custom filter)","Fix the producer so time is epoch seconds/epoch string, not a structured object or null","For strings like '2021-08-20T...' use a string time_type with formats instead of unixtime, or mixed with fallbacks"],"exampleFix":"# before\n<parse>\n  @type json\n  time_key time\n  time_type unixtime   # record: {\"time\": null} -> TimeParseError\n</parse>\n\n# after\n<parse>\n  @type json\n  time_key time\n  time_type unixtime\n  estimate_current_event false\n</parse>\n# plus a filter dropping records without a usable time:\n<filter **>\n  @type record_transformer\n  remove_keys _dummy_\n</filter>","handlingStrategy":"type-guard","validationCode":"value = record['time']\nnext unless value.is_a?(String) || value.is_a?(Numeric)","typeGuard":"def unixtime_like?(v)\n  v.is_a?(String) || v.is_a?(Numeric)\nend","tryCatchPattern":"begin\n  t = numeric_parser.parse(value)\nrescue Fluent::TimeParseError => e\n  log.warn 'bad time field', value: value.inspect, error: e.message\n  next\nend","preventionTips":["Ensure the producer emits the time field as number or numeric string, never null/object","Validate records at the edge (in_http / custom parser) and reject malformed ones early"],"tags":["fluentd","time","parser","unixtime","type-error","runtime"],"backgroundTag":"invalid-input-type","analyzedSha":"dd45c6e18dc7be33b5e5a0f0767bf46307ff5626","analyzedAt":"2026-08-21T16:22:07.332Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}