{"record":{"id":"2fbbd768fcf2aecd","repo":"puppetlabs/puppet","slug":"option-default-to-block-should-not-take-any-arg","errorCode":null,"errorMessage":"%{option} default_to block should not take any arguments","messagePattern":"%(.+?) default_to block should not take any arguments","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/interface/option_builder.rb","lineNumber":105,"sourceCode":"    @option.required = value\n  end\n\n  # Sets a block that will be used to compute the default value for this\n  # option. It will be evaluated when the action is invoked. The block\n  # should take no arguments.\n  # @api public\n  # @dsl Faces\n  def default_to(&block)\n    unless block\n      # TRANSLATORS 'default_to' is a method name and should not be translated\n      raise ArgumentError, _(\"%{option} default_to requires a block\") % { option: @option }\n    end\n    if @option.has_default?\n      raise ArgumentError, _(\"%{option} already has a default value\") % { option: @option }\n    end\n    unless block.arity == 0\n      # TRANSLATORS 'default_to' is a method name and should not be translated\n      raise ArgumentError, _(\"%{option} default_to block should not take any arguments\") % { option: @option }\n    end\n\n    @option.default = block\n  end\nend\n","sourceCodeStart":87,"sourceCodeEnd":111,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/interface/option_builder.rb#L87-L111","documentation":"OptionBuilder#default_to requires the block to take no arguments (`block.arity == 0`, lib/puppet/interface/option_builder.rb:105) because Puppet later calls it as a bare `call`. Any declared parameter — a named one or a splat — makes the arity non-zero and fails at face load.","triggerScenarios":"`default_to { |face| ... }` (arity 1); `default_to { |*args| ... }` (arity -1); a lambda stored in a variable that takes parameters and is passed with `&`.","commonSituations":"Assuming the block receives the face or the option; reusing a generic helper block that echoes its arguments.","solutions":["Drop all block parameters and read state from closures: `default_to { Puppet.settings[:environment] }`","If reusing a parameterized lambda, wrap it: `default_to { compute_default }`","Assert `block.arity == 0` when default blocks come from configuration"],"exampleFix":"# before\ndefault_to { |face| face.setting(:environment) }\n\n# after\ndefault_to { Puppet.settings[:environment] }","handlingStrategy":"validation","validationCode":"block = proc { Puppet.settings[:environment] }\nraise ArgumentError, 'default_to block must take no arguments' unless block.arity == 0\ndefault_to(&block)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write default_to blocks with zero parameters and read state from enclosing scope","Wrap parameterized lambdas instead of passing them directly","Check arity of config-supplied blocks before registration"],"tags":["puppet","faces","dsl","arity","argumenterror"],"backgroundTag":"block-arity-mismatch","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}