{"record":{"id":"0a40739744e91cc8","repo":"puppetlabs/puppet","slug":"option-default-to-requires-a-block","errorCode":null,"errorMessage":"%{option} default_to requires a block","messagePattern":"%(.+?) default_to requires a block","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/interface/option_builder.rb","lineNumber":98,"sourceCode":"  end\n\n  # Sets whether the option is required. If no argument is given it\n  # defaults to setting it as a required option.\n  # @api public\n  # @dsl Faces\n  def required(value = true)\n    @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":80,"sourceCodeEnd":111,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/interface/option_builder.rb#L80-L111","documentation":"OptionBuilder#default_to registers the block that lazily computes an option's default; calling it without a block raises ArgumentError (lib/puppet/interface/option_builder.rb:98). The block is stored via Option#default= and evaluated when the action is invoked, so a literal block is mandatory.","triggerScenarios":"`option '--foo' do default_to end` (no block); `default_to(&config[:default])` where the config value is nil.","commonSituations":"Placeholder DSL left from scaffolding; defaults sourced from a config hash whose key is absent.","solutions":["Pass a literal block: `default_to { 'production' }`","For computed values keep the block argument-free: `default_to { Puppet.settings[:environment] }`","Guard optional defaults: `default_to { config[:default] } if config.key?(:default)`"],"exampleFix":"# before\noption \"--environment\" do\n  default_to\nend\n\n# after\noption \"--environment\" do\n  default_to { \"production\" }\nend","handlingStrategy":"validation","validationCode":"# when the default comes from a variable\nraise ArgumentError, 'default_to needs a block' if default_proc.nil?\ndefault_to(&default_proc) # inside the option block","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always write `default_to { ... }` with a literal, argument-free block","Verify config-driven defaults exist before passing them with `&`","Compute values inside the block via closures, not block parameters"],"tags":["puppet","faces","dsl","block","argumenterror"],"backgroundTag":"missing-block-argument","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}