{"record":{"id":"3485371d0677baf8","repo":"hashicorp/vagrant","slug":"there-was-an-error-loading-a-vagrantfile-the-file-348537","errorCode":null,"errorMessage":"There was an error loading a Vagrantfile. The file being loaded and the error message are shown below. This is usually caused by a syntax error.\n\nPath: %{path}\nLine number: %{line}\nMessage: %{exception_class}: %{message}","messagePattern":"There was an error loading a Vagrantfile\\. The file being loaded and the error message are shown below\\. This is usually caused by a syntax error\\.\n\nPath: %(.+?)\nLine number: %(.+?)\nMessage: %(.+?): %(.+?)","errorType":"exception","errorClass":"Vagrant::Errors::VagrantfileLoadError","httpStatus":null,"severity":"error","filePath":"lib/vagrant/config/loader.rb","lineNumber":313,"sourceCode":"            # Continue raising known Vagrant errors since they already\n            # contain well worded error messages and context.\n            raise\n          rescue Exception => e\n            @logger.error(\"Vagrantfile load error: #{e.message}\")\n            @logger.error(e.backtrace.join(\"\\n\"))\n\n            line = \"(unknown)\"\n            if e.backtrace && e.backtrace[0]\n              e.backtrace[0].split(\":\").each do |part|\n                if part =~ /\\d+/\n                  line = part.to_i\n                  break\n                end\n              end\n            end\n\n            # Report the generic exception\n            raise Errors::VagrantfileLoadError,\n              path: path,\n              line: line,\n              exception_class: e.class,\n              message: e.message\n          end\n        end\n      end\n    end\n  end\nend\n","sourceCodeStart":295,"sourceCodeEnd":324,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/lib/vagrant/config/loader.rb#L295-L324","documentation":"Raised as Vagrant::Errors::VagrantfileLoadError from Config::Loader#procs_for_path (lib/vagrant/config/loader.rb:313) when Kernel.load(path) raises a generic Exception that is not SyntaxError, SystemExit, or a known Vagrant::Errors::VagrantError. It reports the exception class, message, and the best-effort path/line parsed from the backtrace. This covers the top-level execution of the Vagrantfile, distinct from the configure-block evaluation covered by VagrantfileNameError and from parse errors covered by VagrantfileSyntaxError.","triggerScenarios":"A Vagrantfile that parses but whose top-level code raises: require \"aws-sdk\" when the gem is not installed (LoadError), File.read(\"boxes.json\") on a missing file (Errno::ENOENT), NoMethodError on nil at top level, or any custom raise outside Vagrant.configure blocks — all surfaced while Kernel.load executes the file.","commonSituations":"Requiring third-party gems directly in a Vagrantfile instead of using plugins; reading environment-specific JSON/YAML files that are absent on a new checkout; shell-style logic at the top of the file failing on a different OS.","solutions":["Read the Exception class and Message fields in the error, then open the reported Path and Line number","For LoadError on a gem: prefer a Vagrant plugin (vagrant plugin install <name>) plus Vagrant.has_plugin? guards instead of raw require","For Errno::* on file access: guard with File.exist? and build paths relative to the Vagrantfile (File.expand_path(..., __FILE__))","Re-run `vagrant validate` to confirm the file loads cleanly"],"exampleFix":"# before\nrequire \"aws-sdk\"   # LoadError: cannot load such file -- aws-sdk\nVagrant.configure(\"2\") do |config|\n  # ...\nend\n\n# after\n# vagrant plugin install vagrant-aws\nraise \"vagrant-aws plugin required\" unless Vagrant.has_plugin?(\"vagrant-aws\")\nVagrant.configure(\"2\") do |config|\n  # ...\nend","handlingStrategy":"try-catch","validationCode":"# Require nothing at load time you have not verified is present\n%w[json yaml].each do |lib|\n  begin\n    require lib\n  rescue LoadError => e\n    abort \"Vagrantfile dependency missing: #{e.message}\"\n  end\nend","typeGuard":null,"tryCatchPattern":"begin\n  env = Vagrant::Environment.new(cwd: dir)\n  env.vagrantfile\nrescue Vagrant::Errors::VagrantfileLoadError => e\n  abort \"#{e.extra_data[:exception_class]} at #{e.extra_data[:path]}:#{e.extra_data[:line]}: #{e.extra_data[:message]}\"\nend","preventionTips":["Prefer vagrant plugins + Vagrant.has_plugin? over raw require of gems","Guard file reads at Vagrantfile top level with File.exist? and expand paths relative to __FILE__","Keep top-level logic minimal; move complexity into configure blocks or plugins"],"tags":["vagrant","vagrantfile","runtime-error","loaderror","configuration"],"backgroundTag":"config-file-runtime-error","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}