{"record":{"id":"4cfaf067611b382c","repo":"fluent/fluentd","slug":"type-is-required-in-format","errorCode":null,"errorMessage":"@type is required in <format>","messagePattern":"@type is required in <format>","errorType":"exception","errorClass":"Fluent::ConfigError","httpStatus":null,"severity":"error","filePath":"lib/fluent/plugin_helper/formatter.rb","lineNumber":32,"sourceCode":"#    limitations under the License.\n#\n\nrequire 'fluent/plugin'\nrequire 'fluent/plugin/formatter'\nrequire 'fluent/config/element'\nrequire 'fluent/configurable'\n\nmodule Fluent\n  module PluginHelper\n    module Formatter\n      def formatter_create(usage: '', type: nil, conf: nil, default_type: nil)\n        formatter = @_formatters[usage]\n        return formatter if formatter && !type && !conf\n\n        type = if type\n                 type\n               elsif conf && conf.respond_to?(:[])\n                 raise Fluent::ConfigError, \"@type is required in <format>\" unless conf['@type']\n                 conf['@type']\n               elsif default_type\n                 default_type\n               else\n                 raise ArgumentError, \"BUG: both type and conf are not specified\"\n               end\n        formatter = Fluent::Plugin.new_formatter(type, parent: self)\n        config = case conf\n                 when Fluent::Config::Element\n                   conf\n                 when Hash\n                   # in code, programmer may use symbols as keys, but Element needs strings\n                   conf = Hash[conf.map{|k,v| [k.to_s, v]}]\n                   Fluent::Config::Element.new('format', usage, conf, [])\n                 when nil\n                   Fluent::Config::Element.new('format', usage, {}, [])\n                 else\n                   raise ArgumentError, \"BUG: conf must be a Element, Hash (or unspecified), but '#{conf.class}'\"","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/fluent/fluentd/blob/dd45c6e18dc7be33b5e5a0f0767bf46307ff5626/lib/fluent/plugin_helper/formatter.rb#L14-L50","documentation":"Fluent::ConfigError from formatter_create. A formatter plugin (json, ltsv, tsv, csv, stdout, single_value, ...) is selected by its @type; when the helper is given a conf object (Fluent::Config::Element or Hash) with no '@type' entry and neither a type: argument nor a default_type: was passed, it cannot choose a formatter class and fails fast.","triggerScenarios":"formatter_create(usage: 'fmt', conf: conf) where conf is an Element/Hash lacking '@type', with no type: or default_type: supplied. User-facing equivalent: a <format> section in fluent.conf that omits the @type line.","commonSituations":"<format> block missing '@type json'/'@type ltsv'; writing 'type' instead of '@type'; mis-indenting <format> so its @type is parsed as an option of the parent section; plugin code building a Hash programmatically and forgetting the '@type' key.","solutions":["Add an @type line inside the <format> section, e.g. @type json or @type ltsv","In plugin code, pass type: explicitly to formatter_create or supply default_type: so a missing @type falls back instead of raising","Fix the indentation so <format> is nested inside the correct plugin block and its @type is recognized as the section type"],"exampleFix":"# before\n<match app.**>\n  @type stdout\n  <format>\n    output_type json\n  </format>\n</match>\n\n# after\n<match app.**>\n  @type stdout\n  <format>\n    @type json\n  </format>\n</match>","handlingStrategy":"validation","validationCode":"# guard before formatter_create\ntype = type || conf['@type'] if conf.respond_to?(:[])\nraise Fluent::ConfigError, '<format> needs @type' unless type || default_type\nformatter = formatter_create(usage: 'fmt', type: type, conf: conf, default_type: default_type)","typeGuard":null,"tryCatchPattern":"begin\n  formatter_create(usage: usage, conf: conf, default_type: 'json')\nrescue Fluent::ConfigError => e\n  raise Fluent::ConfigError, \"in <format #{usage}>: #{e.message}\"\nend","preventionTips":["Write @type as the first line of every <format> section","Pass default_type: when calling formatter_create with user-supplied conf","Validate config with --dry-run before deployment"],"tags":["fluentd","formatter","configuration","plugin-helper"],"backgroundTag":"missing-type-annotation","analyzedSha":"dd45c6e18dc7be33b5e5a0f0767bf46307ff5626","analyzedAt":"2026-08-21T16:22:07.332Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}