Skip to content

Commit

Permalink
fix: rescue exceptions in deploy tasks, allow deploy to continue (#983)
Browse files Browse the repository at this point in the history
  • Loading branch information
waltjones committed Jul 21, 2020
1 parent 5dfb4e6 commit 34b0a63
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rollbar/capistrano_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def deploy_task(logger, opts = {})
capistrano_300_warning(logger)
logger.info opts[:desc] if opts[:desc]
yield

rescue StandardError => e
logger.error "Error reporting to Rollbar: #{e.inspect}"
end

def deploy_update(capistrano, logger, dry_run, opts = {})
Expand Down
33 changes: 33 additions & 0 deletions spec/rollbar/capistrano_tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@
end
end

context 'when an an exception is raised' do
it "logs the error to the logger" do
expect(::Rollbar::Deploy).to receive(:report)
.and_raise('an API exception')

expect(logger).to receive(:error).with(/an API exception/)

subject.deploy_started(capistrano, logger, dry_run)
end
end

context 'with --dry-run provided' do
let(:dry_run) { true }

Expand Down Expand Up @@ -154,6 +165,17 @@
end
end

context 'when an an exception is raised' do
it "logs the error to the logger" do
expect(::Rollbar::Deploy).to receive(:update)
.and_raise('an API exception')

expect(logger).to receive(:error).with(/an API exception/)

subject.deploy_succeeded(capistrano, logger, dry_run)
end
end

context 'with --dry-run provided' do
let(:dry_run) { true }
let(:deploy_id) { 123 }
Expand Down Expand Up @@ -251,6 +273,17 @@
end
end

context 'when an an exception is raised' do
it "logs the error to the logger" do
expect(::Rollbar::Deploy).to receive(:update)
.and_raise('an API exception')

expect(logger).to receive(:error).with(/an API exception/)

subject.deploy_failed(capistrano, logger, dry_run)
end
end

context 'with --dry-run provided' do
let(:deploy_id) { 123 }
let(:dry_run) { true }
Expand Down

0 comments on commit 34b0a63

Please sign in to comment.