Module: Autobuild::Reporting
- Defined in:
- lib/autobuild/reporting.rb
Overview
The reporting module provides the framework # to run commands in autobuild and report errors # to the user
It does not use a logging framework like Log4r, but it should ;-)
Class Method Summary collapse
-
.<<(reporter) ⇒ Object
Add a new reporter.
- .clear_reporters ⇒ Object
-
.default_report_on_package_failures ⇒ Object
private
Helper that returns the default for on_package_failures.
-
.each_log(&block) ⇒ Object
Iterate on all log files.
- .each_reporter(&iter) ⇒ Object
-
.error(error) ⇒ Object
Reports that the build failed to the user.
- .remove(reporter) ⇒ Object
-
.report(on_package_failures: default_report_on_package_failures) ⇒ Object
Run a block and report known exception If an exception is fatal, the program is terminated using exit().
-
.report_finish_on_error(errors, on_package_failures: default_report_on_package_failures, interrupted_by: nil) ⇒ Object
private
Handle how Reporting.report is meant to finish in case of error(s).
-
.success ⇒ Object
Reports a successful build to the user.
Class Method Details
.<<(reporter) ⇒ Object
Add a new reporter
194 195 196 |
# File 'lib/autobuild/reporting.rb', line 194 def self.<<(reporter) @reporters << reporter end |
.clear_reporters ⇒ Object
202 203 204 |
# File 'lib/autobuild/reporting.rb', line 202 def self.clear_reporters @reporters.clear end |
.default_report_on_package_failures ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Helper that returns the default for on_package_failures
The result depends on the value for Autobuild.debug. It is either :exit if debug is false, or :raise if it is true
131 132 133 134 135 |
# File 'lib/autobuild/reporting.rb', line 131 def self.default_report_on_package_failures if Autobuild.debug then :raise else :exit end end |
.each_log(&block) ⇒ Object
Iterate on all log files
211 212 213 |
# File 'lib/autobuild/reporting.rb', line 211 def self.each_log(&block) Autobuild.logfiles.each(&block) end |
.each_reporter(&iter) ⇒ Object
206 207 208 |
# File 'lib/autobuild/reporting.rb', line 206 def self.each_reporter(&iter) @reporters.each(&iter) end |
.error(error) ⇒ Object
Reports that the build failed to the user
189 190 191 |
# File 'lib/autobuild/reporting.rb', line 189 def self.error(error) each_reporter { |rep| rep.error(error) } end |
.remove(reporter) ⇒ Object
198 199 200 |
# File 'lib/autobuild/reporting.rb', line 198 def self.remove(reporter) @reporters.delete(reporter) end |
.report(on_package_failures: default_report_on_package_failures) ⇒ Object
Run a block and report known exception If an exception is fatal, the program is terminated using exit()
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/autobuild/reporting.rb', line 102 def self.report(on_package_failures: default_report_on_package_failures) begin yield rescue Interrupt => e interrupted = e rescue Autobuild::Exception => e return report_finish_on_error([e], on_package_failures: on_package_failures, interrupted_by: interrupted) end # If ignore_erorrs is true, check if some packages have failed # on the way. If so, raise an exception to inform the user about # it errors = [] Autobuild::Package.each do |_name, pkg| errors.concat(pkg.failures) end report_finish_on_error(errors, on_package_failures: on_package_failures, interrupted_by: interrupted) end |
.report_finish_on_error(errors, on_package_failures: default_report_on_package_failures, interrupted_by: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Handle how Reporting.report is meant to finish in case of error(s)
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/autobuild/reporting.rb', line 143 def self.report_finish_on_error(errors, on_package_failures: default_report_on_package_failures, interrupted_by: nil) if (not_package_error = errors.find { |e| !e.respond_to?(:fatal?) }) raise not_package_error end unless %i[raise report_silent exit_silent].include?(on_package_failures) errors.each { |e| error(e) } end fatal = errors.any?(&:fatal?) unless fatal if interrupted_by raise interrupted_by else return errors end end if on_package_failures == :raise raise interrupted_by if interrupted_by e = if errors.size == 1 then errors.first else CompositeException.new(errors) end raise e elsif %i[report_silent report].include?(on_package_failures) if interrupted_by raise interrupted_by else errors end elsif %i[exit exit_silent].include?(on_package_failures) exit 1 else raise ArgumentError, "unexpected value for on_package_failures: "\ "#{on_package_failures}" end end |
.success ⇒ Object
Reports a successful build to the user
184 185 186 |
# File 'lib/autobuild/reporting.rb', line 184 def self.success each_reporter(&:success) end |