{"record":{"id":"136d3f62cef570b6","repo":"puppetlabs/puppet","slug":"a-block-must-be-given-to-in-tmp-environment","errorCode":null,"errorMessage":"A block must be given to 'in_tmp_environment'","messagePattern":"A block must be given to 'in_tmp_environment'","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pal/pal_impl.rb","lineNumber":241,"sourceCode":"  # @param modulepath [Array<String>] an array of directory paths containing Puppet modules, may be empty, defaults to empty array\n  # @param settings_hash [Hash] a hash of settings - currently not used for anything, defaults to empty hash\n  # @param facts [Hash] optional map of fact name to fact value - if not given will initialize the facts (which is a slow operation)\n  # @param variables [Hash] optional map of fully qualified variable name to value\n  # @return [Object] returns what the given block returns\n  # @yieldparam [Puppet::Pal] context, a context that responds to Puppet::Pal methods\n  #\n  def self.in_tmp_environment(env_name,\n                              modulepath:    [],\n                              settings_hash: {},\n                              facts:         nil,\n                              variables:     {},\n                              &block)\n    assert_non_empty_string(env_name, _(\"temporary environment name\"))\n    # TRANSLATORS: do not translate variable name string in these assertions\n    assert_optionally_empty_array(modulepath, 'modulepath')\n\n    unless block_given?\n      raise ArgumentError, _(\"A block must be given to 'in_tmp_environment'\") # TRANSLATORS 'in_tmp_environment' is a name, do not translate\n    end\n\n    env = Puppet::Node::Environment.create(env_name, modulepath)\n\n    in_environment_context(\n      Puppet::Environments::Static.new(env), # The tmp env is the only known env\n      env, facts, variables, &block\n    )\n  end\n\n  # Defines the context in which to perform puppet operations (evaluation, etc)\n  # The code to evaluate in this context is given in a block.\n  #\n  # The name of an environment (env_name) is always given. The location of that environment on disk\n  # is then either constructed by:\n  # * searching a given envpath where name is a child of a directory on that path, or\n  # * it is the directory given in env_dir (which must exist).\n  #","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pal/pal_impl.rb#L223-L259","documentation":"Puppet::Pal.in_tmp_environment requires a block: the whole PAL API is block-scoped, and the temporary environment (created from env_name + modulepath) exists only inside the block. Calling without a block raises ArgumentError.","triggerScenarios":"Puppet::Pal.in_tmp_environment('demo', modulepath: [m]) with no do...end block; or a wrapper that received &block as nil (caller forgot to forward it).","commonSituations":"Copy-paste from docs dropping the block; passing a method reference/lambda incorrectly; wrapper methods that forget to accept and forward &block.","solutions":["Pass a do...end or { } block to in_tmp_environment","In wrappers, accept &block and forward it explicitly to PAL","Verify with respond_to?(:block_given?) style checks in your wrapper before delegating"],"exampleFix":"# before\nPuppet::Pal.in_tmp_environment('demo', modulepath: [mod])\n\n# after\nPuppet::Pal.in_tmp_environment('demo', modulepath: [mod]) do |pal|\n  # use pal\nend","handlingStrategy":"validation","validationCode":"raise ArgumentError, 'block required' unless block_given?\nPuppet::Pal.in_tmp_environment(name, modulepath: mp, &block)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Forward &block through every wrapper layer of PAL calls","Fail fast in wrappers with block_given? for a clearer message than the library's"],"tags":["puppet","pal","ruby","block"],"backgroundTag":"missing-block-argument","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}