Skip to content

Commit

Permalink
Failed SSH commands show output in error message. [closes hashicorpGH…
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Feb 9, 2011
1 parent 41e98c9 commit c1373f4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@
- Change sudo shell to use `bash` (configurable). [GH-301]
- Can now set mac address of host only network. [GH-294]
- NFS shared folders with spaces now work properly. [GH-293]
- Failed SSH commands now show output in error message. [GH-285]

## 0.7.1 (January 28, 2011)

Expand Down
8 changes: 5 additions & 3 deletions lib/vagrant/ssh/session.rb
Expand Up @@ -75,7 +75,7 @@ def setup_channel_callbacks(channel, command, options, block)
options = { :error_check => true }.merge(options || {})

block ||= Proc.new do |ch, type, data|
check_exit_status(data, command, options) if type == :exit_status && options[:error_check]
check_exit_status(data, command, options, ch[:result]) if type == :exit_status && options[:error_check]

ch[:result] ||= ""
ch[:result] << data if [:stdout, :stderr].include?(type)
Expand All @@ -99,12 +99,14 @@ def setup_channel_callbacks(channel, command, options, block)

# Checks for an erroroneous exit status and raises an exception
# if so.
def check_exit_status(exit_status, commands, options=nil)
def check_exit_status(exit_status, commands, options=nil, output=nil)
if exit_status != 0
output ||= '[no output]'
options = {
:_error_class => Errors::VagrantError,
:_key => :ssh_bad_exit_status,
:command => [commands].flatten.join("\n")
:command => [commands].flatten.join("\n"),
:output => output
}.merge(options || {})

raise options[:_error_class], options
Expand Down
4 changes: 4 additions & 0 deletions templates/locales/en.yml
Expand Up @@ -70,6 +70,10 @@ en:
Vagrant assumes that this means the command failed!
%{command}
The output of the command prior to failing is outputted below:
%{output}
ssh_connection_refused: |-
SSH connection was refused! This usually happens if the VM failed to
boot properly. Some steps to try to fix this: First, try reloading your
Expand Down

0 comments on commit c1373f4

Please sign in to comment.