Skip to content

Commit

Permalink
raise Veewee::Error instead of exiting
Browse files Browse the repository at this point in the history
  • Loading branch information
jedi4ever committed Apr 18, 2012
1 parent a4cf572 commit 04859f8
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 28 deletions.
2 changes: 1 addition & 1 deletion bin/veewee
Expand Up @@ -18,5 +18,5 @@ begin
::Veewee::CLI.start(ARGV,:env => env)

rescue Veewee::Error => e
puts "#{e}"
env.ui.error "#{e}"
end
4 changes: 2 additions & 2 deletions lib/veewee/config.rb
Expand Up @@ -48,11 +48,11 @@ def load_veewee_config()
env.ui.error "Some method got an error in the configfile - Sorry"
env.ui.error $!
env.ui.error e.message
exit -1
raise Veewee::Error "Some method got an error in the configfile - Sorry"
rescue Error => e
env.ui.error "Error processing configfile - Sorry"
env.ui.error e.message
exit -1
raise Veewee::Error "Error processing configfile - Sorry"
end
return self
end
Expand Down
8 changes: 4 additions & 4 deletions lib/veewee/provider/core/box/exec.rb
Expand Up @@ -18,13 +18,13 @@ def exec(command,options={})
result=self.ssh_execute(self.ip_address,command,new_options)
return result
rescue RuntimeError => ex
ui.error("Error executing command #{command} : #{ex}",:prefix => false)
raise Veewee::SshError, ex
error= "Error executing command #{command} : #{ex}"
error+="\n"+ex
raise Veewee::SshError, error
end
end
rescue Net::SSH::AuthenticationFailed => ex
ui.error("Authentication failure",:prefix => false)
raise Veewee::SshError, ex
raise Veewee::SshError, "Authentication failure\n"+ex
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/veewee/provider/core/helper/ssh.rb
Expand Up @@ -47,7 +47,7 @@ def when_ssh_login_works(ip="127.0.0.1", options = { } , &block)
end
rescue Timeout::Error
ui.error "Ssh timeout #{options[:timeout]} sec has been reached."
exit -1
raise Veewee::Error, "Ssh timeout #{options[:timeout]} sec has been reached."
end
ui.info ""
return false
Expand Down
2 changes: 1 addition & 1 deletion lib/veewee/provider/core/helper/tcp.rb
Expand Up @@ -39,7 +39,7 @@ def guess_free_port(min_port,max_port)

if guessed_port.nil?
ui.error "No free port available: tried #{min_port}..#{max_port}"
exit -1
raise Veewee::Error, "No free port available: tried #{min_port}..#{max_port}"
else
ui.info "Found port #{guessed_port} available"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/veewee/provider/kvm/box/destroy.rb
Expand Up @@ -6,7 +6,7 @@ module BoxCommand
def destroy(options={})
if @connection.servers.all(:name => name).nil?
env.ui.error "Error:: You tried to destroy a non-existing box '#{name}'"
exit -1
raise Veewee::Error,"Error:: You tried to destroy a non-existing box '#{name}'"
end

self.poweroff if running?
Expand Down
3 changes: 1 addition & 2 deletions lib/veewee/provider/parallels/box/destroy.rb
Expand Up @@ -5,8 +5,7 @@ module BoxCommand

def destroy(options={})
unless self.exists?
ui.error "Error:: You tried to destroy a non-existing box '#{name}'"
exit -1
raise Veewee::Error, "Error:: You tried to destroy a non-existing box '#{name}'"
end

if self.running?
Expand Down
4 changes: 1 addition & 3 deletions lib/veewee/provider/virtualbox/box/destroy.rb
Expand Up @@ -6,8 +6,7 @@ module BoxCommand
def destroy(option={})

unless self.exists?
ui.error "Error:: You tried to destroy a non-existing box '#{name}'"
exit -1
raise Veewee::Error, "Error:: You tried to destroy a non-existing box '#{name}'"
end

# If it has a save state,remove that first
Expand Down Expand Up @@ -53,7 +52,6 @@ def destroy(option={})
ui.info "We tried to delete the disk file via virtualbox '#{location} but failed"
ui.info "Removing it manually"
FileUtils.rm(location)
exit -1
end
break
end
Expand Down
3 changes: 1 addition & 2 deletions lib/veewee/provider/virtualbox/box/export_vagrant.rb
Expand Up @@ -54,8 +54,7 @@ def export_vagrant(options)
box_path=path1.relative_path_from(path2).to_s

if File.exists?("#{box_path}")
ui.info "box #{name}.box already exists"
exit
raise Veewee::Error, "box #{name}.box already exists"
end

ui.info "Executing vagrant voodoo:"
Expand Down
10 changes: 5 additions & 5 deletions lib/veewee/provider/virtualbox/box/helper/console_type.rb
Expand Up @@ -48,11 +48,11 @@ def send_keycode(keycode)
env.logger.info "#{command}"
sshresult=shell_exec("#{command}",{:mute => true})
unless sshresult.stdout.index("E_ACCESSDENIED").nil?
ui.error "There was an error typing the commands on the console"
ui.error "Probably the VM did not get started."
ui.error ""
ui.error "#{sshresult.stdout}"
exit -1
error= "There was an error typing the commands on the console"
error+="Probably the VM did not get started."
error+= ""
error+= "#{sshresult.stdout}"
raise Veewee::Error, error
end
end

Expand Down
5 changes: 2 additions & 3 deletions lib/veewee/provider/virtualbox/box/up.rb
Expand Up @@ -6,8 +6,7 @@ module BoxCommand
def up(options={})

unless self.exists?
ui.error "Error:: You tried to up a non-existing box '#{name}'"
exit -1
raise Veewee::Error, "Error:: You tried to up a non-existing box '#{name}'"
end

gui_enabled=options['nogui']==true ? false : true
Expand All @@ -30,7 +29,7 @@ def up(options={})
self.add_ssh_nat_mapping
end

self.suppress_messages
self.suppress_messages

# Once assembled we start the machine
env.logger.info "Started the VM with GUI Enabled? #{gui_enabled}"
Expand Down
3 changes: 1 addition & 2 deletions lib/veewee/provider/vmfusion/box/destroy.rb
Expand Up @@ -5,8 +5,7 @@ module BoxCommand

def destroy(options={})
unless raw.exists?
env.ui.error "Error:: You tried to destroy a non-existing box '#{name}'"
exit -1
raise Veewee::Error, "Error:: You tried to destroy a non-existing box '#{name}'"
end

raw.halt if raw.state=="running"
Expand Down
2 changes: 1 addition & 1 deletion lib/veewee/provider/vmfusion/box/helper/vnc.rb
Expand Up @@ -29,7 +29,7 @@ def guess_vnc_port

if guessed_port.nil?
env.ui.info "No free VNC port available: tried #{min_port}..#{max_port}"
exit -1
raise Veewee::Error, "No free VNC port available: tried #{min_port}..#{max_port}"
else
env.ui.info "Found VNC port #{guessed_port} available"
end
Expand Down

0 comments on commit 04859f8

Please sign in to comment.