{"record":{"id":"48451b87b9e7d854","repo":"puppetlabs/puppet","slug":"option-already-has-a-default-value","errorCode":null,"errorMessage":"%{option} already has a default value","messagePattern":"%(.+?) already has a default value","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/interface/option_builder.rb","lineNumber":101,"sourceCode":"  # 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":83,"sourceCodeEnd":111,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/interface/option_builder.rb#L83-L111","documentation":"OptionBuilder#default_to raises when `@option.has_default?` is already true — an option can carry only one default (lib/puppet/interface/option_builder.rb:101). Puppet does not chain or override defaults, so the second declaration is a definition error, not a replacement.","triggerScenarios":"Two `default_to` blocks in one option block; a `default_to` call after the Option already got a default via `opt.default = proc`.","commonSituations":"Copy-pasted option blocks both carrying defaults; environment-specific tuning that appends a second default instead of editing the first.","solutions":["Keep a single `default_to` block and put the branching inside it: `default_to { env == :test ? 'dev' : 'production' }`","Delete the stale default after consolidating","Remember `required` + `default_to` is also rejected (see errors 280/282) — pick exactly one of required/default per option"],"exampleFix":"# before\noption \"--environment\" do\n  default_to { \"production\" }\n  default_to { \"development\" }\nend\n\n# after\noption \"--environment\" do\n  default_to { Puppet.settings[:environment] }\nend","handlingStrategy":"validation","validationCode":"# on an Option object before setting a default\nraise ArgumentError, 'default already set' if opt.has_default?\nopt.default = -> { 'production' }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep exactly one default per option; branch inside the block instead of redeclaring","Grep option blocks for multiple `default_to` lines before committing","Remember defaults are single-slot — there is no override or chain semantics"],"tags":["puppet","faces","dsl","duplicate","argumenterror"],"backgroundTag":"duplicate-declaration","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}