Skip to content

Commit

Permalink
fix various file-not-found exception handlers
Browse files Browse the repository at this point in the history
* we were catching the wrong exception in most cases, leaving the exceptions
  to propgate to weird places
* clean up one area that would just catch all exceptions and print the
  message, leaving us without a backtrace

Change-Id: I0aa5fe27e6a822555190630e142d23c2f59c28de
  • Loading branch information
vito committed Feb 2, 2012
1 parent ec60346 commit 9f56a1a
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions lib/cli/commands/apps.rb
Expand Up @@ -191,7 +191,7 @@ def files(appname, path='/')
instance = @options[:instance] || '0'
content = client.app_files(appname, path, instance)
display content
rescue VMC::Client::NotFound => e
rescue VMC::Client::TargetError
err 'No such file or directory'
end

Expand Down Expand Up @@ -691,7 +691,7 @@ def grab_logs(appname, instance)
begin
content = client.app_files(appname, path, instance)
display_logfile(path, content, instance)
rescue VMC::Client::NotFound
rescue VMC::Client::TargetError
end
end
end
Expand All @@ -705,13 +705,14 @@ def grab_crash_logs(appname, instance, was_staged=false)
instance = map[instance] if map[instance]

%w{
/logs/err.log /logs/staging.log /app/logs/stderr.log
/app/logs/stdout.log /app/logs/startup.log /app/logs/migration.log
/logs/err.log /logs/staging.log /logs/migration.log
/app/logs/stderr.log /app/logs/stdout.log /app/logs/startup.log
/app/logs/migration.log
}.each do |path|
begin
content = client.app_files(appname, path, instance)
display_logfile(path, content, instance)
rescue VMC::Client::NotFound
rescue VMC::Client::TargetError
end
end
end
Expand All @@ -729,6 +730,8 @@ def grab_startup_tail(appname, since = 0)
display tail.join("\n") if new_lines > 0
end
since + new_lines
rescue VMC::Client::TargetError
0
end

def provisioned_services_apps_hash
Expand Down Expand Up @@ -842,24 +845,23 @@ def do_start(appname, push=false)
loop do
display '.', false unless count > TICKER_TICKS
sleep SLEEP_TIME
begin
break if app_started_properly(appname, count > HEALTH_TICKS)
if !crashes(appname, false, start_time).empty?
# Check for the existance of crashes
display "\nError: Application [#{appname}] failed to start, logs information below.\n".red
grab_crash_logs(appname, '0', true)
if push and !no_prompt
display "\n"
delete_app(appname, false) if ask "Delete the application?", :default => true
end
failed = true
break
elsif count > TAIL_TICKS
log_lines_displayed = grab_startup_tail(appname, log_lines_displayed)

break if app_started_properly(appname, count > HEALTH_TICKS)

if !crashes(appname, false, start_time).empty?
# Check for the existance of crashes
display "\nError: Application [#{appname}] failed to start, logs information below.\n".red
grab_crash_logs(appname, '0', true)
if push and !no_prompt
display "\n"
delete_app(appname, false) if ask "Delete the application?", :default => true
end
rescue => e
err(e.message, '')
failed = true
break
elsif count > TAIL_TICKS
log_lines_displayed = grab_startup_tail(appname, log_lines_displayed)
end

count += 1
if count > GIVEUP_TICKS # 2 minutes
display "\nApplication is taking too long to start, check your logs".yellow
Expand Down Expand Up @@ -1060,7 +1062,7 @@ def all_files(appname, path)
entry[:index],
"====> [#{entry[:index]}: #{path}] <====\n".bold
)
rescue VMC::Client::NotFound
rescue VMC::Client::TargetError
end
end
end
Expand Down

0 comments on commit 9f56a1a

Please sign in to comment.