hashicorp/vagrant · error · VagrantPlugins::CloudCommand::Errors::Unexpected

An unexpected error occurred: %{error}

Error message

An unexpected error occurred: %{error}

What it means

Vagrant::Errors::Unexpected is the catch-all of the cloud client wrapper's `with_error_handling`: any VagrantCloud::Error::ClientError raised by the vagrant-cloud gem during an API call — i.e. a failure this wrapper does not map to Unauthorized, BadRequest, NotAcceptable, or SocketError — is re-raised as Unexpected carrying the original message. The underlying message and backtrace are logged only at debug level, so the default output gives no cause.

Source

Thrown at plugins/commands/cloud/client/client.rb:184

        if !t.nil?
          Vagrant::Util::CredentialScrubber.sensitive(t)
          return t
        end

        @logger.debug("No authentication token in environment or #{token_path}")

        nil
      end

      protected

      def with_error_handling(&block)
        yield
      rescue VagrantCloud::Error::ClientError => e
        @logger.debug("vagrantcloud request error:")
        @logger.debug(e.message)
        @logger.debug(e.backtrace.join("\n"))
        raise Errors::Unexpected, error: e.message
      rescue Excon::Error::Unauthorized
        @logger.debug("Unauthorized!")
        raise Errors::Unauthorized
      rescue Excon::Error::BadRequest => e
        @logger.debug("Bad request:")
        @logger.debug(e.message)
        @logger.debug(e.backtrace.join("\n"))
        parsed_response = JSON.parse(e.response.body)
        errors = parsed_response["errors"].join("\n")
        raise Errors::ServerError, errors: errors
      rescue Excon::Error::NotAcceptable => e
        @logger.debug("Got unacceptable response:")
        @logger.debug(e.message)
        @logger.debug(e.backtrace.join("\n"))

        parsed_response = JSON.parse(e.response.body)

        if two_factor = parsed_response['two_factor']

View on GitHub (pinned to 35f3160f4a)

Solutions

  1. Re-run with debug logging to surface the swallowed cause: `VAGRANT_LOG=debug vagrant cloud auth whoami 2>&1 | grep -A20 'vagrantcloud request error'`
  2. Verify auth state with `vagrant cloud auth whoami` and re-login (`vagrant cloud auth login`) if the token is stale
  3. Upgrade Vagrant so the bundled vagrant-cloud gem matches the current API
  4. Check https://status.hashicorp.com for a Vagrant Cloud incident, then retry

Example fix

# before
vagrant cloud box create myorg/mybox
# after (surface the hidden underlying error and backtrace)
VAGRANT_LOG=debug vagrant cloud box create myorg/mybox 2>&1 | grep -A20 'vagrantcloud request error'
Defensive patterns

Strategy: try-catch

Validate before calling

# Cheap preflight before a batch of cloud commands
require "excon"
begin
  Excon.get(ENV["VAGRANT_SERVER_URL"] || "https://vagrantcloud.com", timeout: 5)
rescue Excon::Error => e
  abort "Vagrant Cloud preflight failed: #{e.class} — fix connectivity before running cloud commands"
end

Type guard

# Distinguish the catch-all from specific cloud errors before handling
def unexpected_cloud_error?(e)
  e.is_a?(Vagrant::Errors::Unexpected)
end

Try / catch

begin
  client.whoami(token)
rescue Vagrant::Errors::Unexpected => e
  # default output hides the cause; log it and re-raise or alert
  logger.fatal("vagrant cloud call failed: #{e.message}")
  raise
end

Prevention

When it happens

Trigger: Any `vagrant cloud ...` command that performs an API request (auth login/logout, whoami, box/version/provider CRUD, publish, search) and receives an error response outside the specifically handled set, or any gem-level client failure inside VagrantCloud::Account / VagrantCloud::Box operations.

Common situations: A Vagrant Cloud incident returning 5xx; a vagrant-cloud gem version bundled with an older Vagrant speaking an out-of-date API; a malformed or expired token producing an unmapped 4xx; a custom VAGRANT_SERVER_URL returning unexpected payloads.

Related errors


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