{"record":{"id":"1078a63944f9f67c","repo":"puppetlabs/puppet","slug":"default-value-for-name-is-a-class-name-not","errorCode":null,"errorMessage":"default value for %{name} is a %{class_name}, not a proc","messagePattern":"default value for %(.+?) is a %(.+?), not a proc","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/interface/option.rb","lineNumber":133,"sourceCode":"    !!@optional_argument\n  end\n\n  def required?\n    !!@required\n  end\n\n  def has_default?\n    !!@default\n  end\n\n  def default=(proc)\n    if required\n      raise ArgumentError, _(\"%{name} can't be optional and have a default value\") % { name: self }\n    end\n\n    unless proc.is_a? Proc\n      # TRANSLATORS 'proc' is a Ruby block of code\n      raise ArgumentError, _(\"default value for %{name} is a %{class_name}, not a proc\") %\n                           { name: self, class_name: proc.class.name.inspect }\n    end\n    @default = proc\n  end\n\n  def default\n    @default and @default.call\n  end\n\n  attr_reader :parent, :name, :aliases, :optparse, :required\n\n  def required=(value)\n    if has_default?\n      raise ArgumentError, _(\"%{name} can't be optional and have a default value\") % { name: self }\n    end\n\n    @required = value\n  end","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/interface/option.rb#L115-L151","documentation":"Puppet::Interface::Option#default= only accepts a Proc, because the default is evaluated lazily via `@default.call` in Option#default (lib/puppet/interface/option.rb:133). Assigning any non-callable object (String, Symbol, Method) raises ArgumentError naming the actual class. The Faces DSL `default_to { ... }` always wraps its block, so this is hit only through direct Option manipulation.","triggerScenarios":"`opt.default = \"production\"` (String); `opt.default = method(:default_env)` — a Method object is not a Proc and fails `proc.is_a? Proc`; assigning a configuration value read from YAML/JSON.","commonSituations":"Migrating static hash-of-defaults code to Option objects; choosing `method(:sym)` for readability; JSON-driven option configuration supplying scalar defaults.","solutions":["Wrap the value in a Proc: `opt.default = -> { 'production' }`","For Method objects use `opt.default = method(:default_env).to_proc`, which does return a Proc","Prefer the DSL `default_to { 'production' }`, which enforces the block for you"],"exampleFix":"# before\nopt.default = \"production\"\n\n# after\nopt.default = -> { \"production\" }","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"# Ruby — narrow to Proc before assigning\ndef proc!(value, what)\n  return value if value.is_a?(Proc)\n  raise ArgumentError, \"#{what} must be a Proc, got #{value.class}\"\nend\n\nopt.default = proc!(candidate, 'default')","tryCatchPattern":null,"preventionTips":["Use the DSL `default_to { ... }` instead of touching Option#default= directly","Remember `->() {}` and `proc {}` are Procs, but `method(:x)` is not — convert with `.to_proc`","Never assign scalars (String/Symbol) as defaults; defaults are lazy computations, not values"],"tags":["puppet","faces","dsl","proc","argumenterror"],"backgroundTag":"wrong-argument-type","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}