{"record":{"id":"48e29ab821869b74","repo":"heartcombo/simple_form","slug":"a-block-is-required-as-argument-to-wrapper","errorCode":null,"errorMessage":"A block is required as argument to wrapper","messagePattern":"A block is required as argument to wrapper","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/simple_form/wrappers/builder.rb","lineNumber":71,"sourceCode":"          @components << Leaf.new(name, options)\n        end\n      end\n\n      def optional(name, options = {}, &block)\n        @options[name] = false\n        use(name, options)\n      end\n\n      def wrapper(name, options = nil)\n        if block_given?\n          name, options = nil, name if name.is_a?(Hash)\n          builder = self.class.new(@options)\n          options ||= {}\n          options[:tag] = :div if options[:tag].nil?\n          yield builder\n          @components << Many.new(name, builder.to_a, options)\n        else\n          raise ArgumentError, \"A block is required as argument to wrapper\"\n        end\n      end\n\n      def to_a\n        @components\n      end\n    end\n  end\nend\n","sourceCodeStart":53,"sourceCodeEnd":81,"githubUrl":"https://github.com/heartcombo/simple_form/blob/18f38aad0bdeca2ba1815043b94d96fdbbe6a325/lib/simple_form/wrappers/builder.rb#L53-L81","documentation":"Inside a config.wrappers block, b.wrapper(name, options) defines a nested group of components (a Wrappers::Many) built by yielding a fresh Builder to the block; the block is what populates the group, so calling b.wrapper without one raises ArgumentError rather than registering an empty wrapper (lib/simple_form/wrappers/builder.rb:71). Single components are added with b.use / b.optional instead.","triggerScenarios":"config.wrappers :default do |b| b.wrapper :addons end (missing do...end); passing components as extra positional args (b.wrapper :addons, :input); confusing b.wrapper (nested group, block required) with b.use (single leaf component).","commonSituations":"Hand-editing a long initializer and losing the do...end; merge conflicts in wrapper config; learning the wrapper DSL and mixing up use and wrapper.","solutions":["Supply a block: b.wrapper :addons do |w| w.use :prefix; w.use :input; w.use :suffix end","If you only wanted a single component, use b.use :input (or b.optional :pattern) instead of b.wrapper","Restart the app after fixing the initializer so the corrected wrappers are re-registered"],"exampleFix":"# before\nSimpleForm.setup do |config|\n  config.wrappers :default do |b|\n    b.wrapper :addons   # ArgumentError: block required\n  end\nend\n\n# after\nSimpleForm.setup do |config|\n  config.wrappers :default do |b|\n    b.wrapper :addons do |w|\n      w.use :prefix\n      w.use :input\n      w.use :suffix\n    end\n  end\nend","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"begin\n  require Rails.root.join('config/initializers/simple_form')\nrescue ArgumentError => e\n  abort \"Fix config/initializers/simple_form.rb (missing block in b.wrapper?): #{e.message}\"\nend","preventionTips":["Treat b.wrapper as always taking a do...end block; use b.use / b.optional for single leaf components","Reboot the app or run a view spec right after editing wrapper config so DSL mistakes fail early","Keep wrapper definitions small and covered by view specs to catch merge-damage"],"tags":["simple-form","wrapper-builder","argument-error","block","dsl","configuration"],"backgroundTag":"missing-required-block","analyzedSha":"18f38aad0bdeca2ba1815043b94d96fdbbe6a325","analyzedAt":"2026-08-21T18:23:08.988Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}