{"record":{"id":"6cb819e2d4ea7f5b","repo":"puppetlabs/puppet","slug":"the-environment-directory-env-dir-does-not-ex","errorCode":null,"errorMessage":"The environment directory '%{env_dir}' does not exist","messagePattern":"The environment directory '%(.+?)' does not exist","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pal/pal_impl.rb","lineNumber":300,"sourceCode":"                          env_dir:       nil,\n                          envpath:       nil,\n                          facts:         nil,\n                          variables:     {},\n                          &block)\n    # TRANSLATORS terms in the assertions below are names of terms in code\n    assert_non_empty_string(env_name, 'env_name')\n    assert_optionally_empty_array(modulepath, 'modulepath', true)\n    assert_optionally_empty_array(pre_modulepath, 'pre_modulepath', false)\n    assert_optionally_empty_array(post_modulepath, 'post_modulepath', false)\n    assert_mutually_exclusive(env_dir, envpath, 'env_dir', 'envpath')\n\n    unless block_given?\n      raise ArgumentError, _(\"A block must be given to 'in_environment'\") # TRANSLATORS 'in_environment' is a name, do not translate\n    end\n\n    if env_dir\n      unless Puppet::FileSystem.exist?(env_dir)\n        raise ArgumentError, _(\"The environment directory '%{env_dir}' does not exist\") % { env_dir: env_dir }\n      end\n\n      # a nil modulepath for env_dir means it should use its ./modules directory\n      mid_modulepath = modulepath.nil? ? [Puppet::FileSystem.expand_path(File.join(env_dir, 'modules'))] : modulepath\n\n      env = Puppet::Node::Environment.create(env_name, pre_modulepath + mid_modulepath + post_modulepath)\n      environments = Puppet::Environments::StaticDirectory.new(env_name, env_dir, env) # The env being used is the only one...\n    else\n      assert_non_empty_string(envpath, 'envpath')\n\n      # The environment is resolved against the envpath. This is setup without a basemodulepath\n      # The modulepath defaults to the 'modulepath' in the found env when \"Directories\" is used\n      #\n      if envpath.is_a?(String) && envpath.include?(File::PATH_SEPARATOR)\n        # potentially more than one directory to search\n        env_loaders = Puppet::Environments::Directories.from_path(envpath, [])\n        environments = Puppet::Environments::Combined.new(*env_loaders)\n      else","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pal/pal_impl.rb#L282-L318","documentation":"in_environment with the env_dir option verifies the directory exists (Puppet::FileSystem.exist?) before building the environment; env_dir is where the environment lives on disk and its modules/ subdirectory becomes the default modulepath. A missing directory raises ArgumentError naming the path.","triggerScenarios":"Puppet::Pal.in_environment('prod', env_dir: '/nonexistent/environments/prod'); relative paths that resolve against an unexpected cwd; fixture directories never created in tests.","commonSituations":"Path typos; running the tool on a different machine than the Puppet code lives on; test specs that assume spec/fixtures was generated; relative vs absolute path confusion.","solutions":["Verify the path: File.directory?(File.expand_path(env_dir)) before calling","Create the directory (and its modules/ layout) or fix the typo","Pass an absolute path, or use envpath pointing at the parent of the environments tree"],"exampleFix":"# before\nPuppet::Pal.in_environment('prod', env_dir: 'environments/prod')\n\n# after\nenv_dir = File.expand_path('spec/fixtures/environments/prod', __dir__)\nraise ArgumentError, \"missing #{env_dir}\" unless File.directory?(env_dir)\nPuppet::Pal.in_environment('prod', env_dir: env_dir) { |pal| }","handlingStrategy":"validation","validationCode":"env_dir = File.expand_path(env_dir)\nraise ArgumentError, \"env_dir #{env_dir} not found\" unless File.directory?(env_dir)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass absolute env_dir paths (expand against __dir__ in tools)","Create test fixture environment directories in spec setup, not lazily"],"tags":["puppet","pal","environment","filesystem"],"backgroundTag":"directory-not-found","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}