-
Notifications
You must be signed in to change notification settings - Fork 390
/
rake.rb
66 lines (55 loc) · 1.86 KB
/
rake.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# frozen_string_literal: true
# This is not bulletproof, but if this file is executed before a task
# definition, we can grab tasks descriptions and locations.
# See: https://goo.gl/ksn6PE
Rake::TaskManager.record_task_metadata = true
module Airbrake
module Rake
# Redefine +Rake::Task#execute+, so it can report errors to Airbrake.
module Task
# A wrapper around the original +#execute+, that catches all errors and
# notifies Airbrake.
#
# rubocop:disable Lint/RescueException
def execute(args = nil)
super(args)
rescue Exception => ex
notify_airbrake(ex, args)
raise ex
end
# rubocop:enable Lint/RescueException
private
def notify_airbrake(exception, args)
notice = Airbrake.build_notice(exception)
notice[:context][:component] = 'rake'
notice[:context][:action] = name
notice[:params].merge!(
rake_task: task_info,
execute_args: args,
argv: ARGV.join(' '),
)
Airbrake.notify_sync(notice)
end
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize
def task_info
info = {}
info[:name] = name
info[:timestamp] = timestamp.to_s
info[:investigation] = investigation
info[:full_comment] = full_comment if full_comment
info[:arg_names] = arg_names if arg_names.any?
info[:arg_description] = arg_description if arg_description
info[:locations] = locations if locations.any?
info[:sources] = sources if sources.any?
if prerequisite_tasks.any?
info[:prerequisite_tasks] = prerequisite_tasks.map do |p|
p.__send__(:task_info)
end
end
info
end
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/AbcSize
end
end
end
Rake::Task.prepend(Airbrake::Rake::Task)