Permalink
Browse files

raise Veewee::Error instead of exiting

  • Loading branch information...
1 parent a4cf572 commit 04859f80845c26eda312583e69da984e214f62d7 @jedi4ever committed Apr 18, 2012
View
@@ -18,5 +18,5 @@ begin
::Veewee::CLI.start(ARGV,:env => env)
rescue Veewee::Error => e
- puts "#{e}"
+ env.ui.error "#{e}"
end
View
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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?
@@ -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?
@@ -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
@@ -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
@@ -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:"
@@ -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
@@ -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
@@ -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}"
@@ -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"
@@ -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

0 comments on commit 04859f8

Please sign in to comment.