diff --git a/lib/train/extras/command_wrapper.rb b/lib/train/extras/command_wrapper.rb index abda3845..d7054228 100644 --- a/lib/train/extras/command_wrapper.rb +++ b/lib/train/extras/command_wrapper.rb @@ -162,16 +162,16 @@ class CommandWrapper include_options WindowsCommand def self.load(transport, options) - if transport.os.unix? + if transport.platform.unix? return nil unless LinuxCommand.active?(options) res = LinuxCommand.new(transport, options) verification_res = res.verify if verification_res msg, reason = verification_res - raise Train::UserError.new("Sudo failed: #{msg}", reason) + raise Train::UserError, "Sudo failed: #{msg}", reason end res - elsif transport.os.windows? + elsif transport.platform.windows? res = WindowsCommand.new(transport, options) res end diff --git a/lib/train/platforms/detect/helpers/os_common.rb b/lib/train/platforms/detect/helpers/os_common.rb index 88af6dad..7fb070e6 100644 --- a/lib/train/platforms/detect/helpers/os_common.rb +++ b/lib/train/platforms/detect/helpers/os_common.rb @@ -31,6 +31,12 @@ def unix_file_exist?(path) def command_output(cmd) res = @backend.run_command(cmd).stdout + # When you try to execute command using ssh connction as root user and you have provided ssh user identity file + # it gives standard output to login as authorised user other than root. To show this standard ouput as an error + # to user we are matching the string of stdout and raising the error here so that user gets exact information. + if @backend.class.to_s == "Train::Transports::SSH::Connection" && res =~ /Please login as the user/ + raise Train::UserError, "SSHFailed: #{res}" + end res.strip! unless res.nil? res end