hashicorp/vagrant · error · Vagrant::Errors::BoxFileNotExist

The file you are attempting to upload does not exist. Please

Error message

The file you are attempting to upload does not exist. Please recheck that the file exists and was passed in correctly. File: %{file}

What it means

Vagrant::Errors::BoxFileNotExist is raised by `vagrant cloud publish` when the local box-file argument exists as a string but `File.file?` is false — the path is missing, points to a directory, or dangles as a broken symlink. The check runs before login and any API call, so nothing remote has happened when you see it.

Source

Thrown at plugins/commands/cloud/publish.rb:81

          end

          # Parse the options
          argv = parse_options(opts)
          return if !argv

          if argv.length < 3 || # missing required arguments
              argv.length > 4 || # too many arguments
              (argv.length < 4 && !options.key?(:url)) || # file argument required if url is not provided
              (argv.length > 3 && options.key?(:url)) # cannot provide url and file argument
            raise Vagrant::Errors::CLIInvalidUsage,
              help: opts.help.chomp
          end

          org, box_name = argv.first.split('/', 2)
          _, version, provider_name, box_file = argv

          if box_file && !File.file?(box_file)
            raise Vagrant::Errors::BoxFileNotExist,
              file: box_file
          end

          @client = client_login(@env)
          params = options.slice(:private, :release, :url, :short_description,
            :description, :version_description, :checksum, :checksum_type,
            :architecture, :default_architecture)

          # Display output to user describing action to be taken
          display_preamble(org, box_name, version, provider_name, params)

          if !options[:force]
            cont = @env.ui.ask(I18n.t("cloud_command.continue"))
            return 1 if cont.strip.downcase != "y"
          end

          # Load up all the models we'll need to publish the asset
          box = load_box(org, box_name, @client.token)

View on GitHub (pinned to 35f3160f4a)

Solutions

  1. Verify from the same shell you invoke vagrant in: `ls -l ./box.box`
  2. Use an absolute path: `vagrant cloud publish myorg/mybox 1.0.0 virtualbox "$PWD/box.box"`
  3. If the box file is hosted remotely, drop the file argument and pass --url instead

Example fix

# before (wrong cwd, relative path)
vagrant cloud publish myorg/mybox 1.0.0 virtualbox box.box
# after
vagrant cloud publish myorg/mybox 1.0.0 virtualbox "$PWD/box.box"
Defensive patterns

Strategy: validation

Validate before calling

# Fail with your own message before invoking vagrant
box_file = File.expand_path(ARGV[0] || "")
unless File.file?(box_file)
  abort "box file missing or not a regular file: #{box_file}"
end
exec "vagrant", "cloud", "publish", org_box, version, provider, box_file

Type guard

# Guard the path value itself before it reaches the CLI
def valid_box_file?(path)
  path.is_a?(String) && !path.strip.empty? && File.file?(File.expand_path(path))
end

Try / catch

begin
  env.cli(%w[cloud publish], org_box, version, provider, box_file)
rescue Vagrant::Errors::BoxFileNotExist => e
  $stderr.puts "staged file vanished: #{e.message}"
  exit 66 # EX_NOINPUT
end

Prevention

When it happens

Trigger: Passing a typo'd or relative path that does not resolve from the current working directory; passing a directory or a symlink to a deleted target as the fourth positional; a shell variable with trailing whitespace or a newline corrupting the path.

Common situations: Running publish from a different directory than where the .box file lives; CI checkout paths differing from local ones; files staged on another machine or in an unmounted share; names with spaces quoted inconsistently.

Related errors


AI-assisted analysis of hashicorp/vagrant@35f3160f4a (2026-08-21). Data as JSON: /api/errors/ba6719ebf448e08a. Report an issue: GitHub.