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

Class Method Details

.<<(reporter) ⇒ Object

Add a new reporter



196
197
198
# File 'lib/autobuild/reporting.rb', line 196

def self.<<(reporter)
    @reporters << reporter
end

.clear_reportersObject



204
205
206
# File 'lib/autobuild/reporting.rb', line 204

def self.clear_reporters
    @reporters.clear
end

.default_report_on_package_failuresObject

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
136
# 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



213
214
215
# File 'lib/autobuild/reporting.rb', line 213

def self.each_log(&block)
    Autobuild.logfiles.each(&block)
end

.each_reporter(&iter) ⇒ Object



208
209
210
# File 'lib/autobuild/reporting.rb', line 208

def self.each_reporter(&iter)
    @reporters.each(&iter)
end

.error(error) ⇒ Object

Reports that the build failed to the user



191
192
193
# File 'lib/autobuild/reporting.rb', line 191

def self.error(error)
    each_reporter { |rep| rep.error(error) }
end

.remove(reporter) ⇒ Object



200
201
202
# File 'lib/autobuild/reporting.rb', line 200

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)

Parameters:

  • on_package_failures (Symbol) (defaults to: default_report_on_package_failures)

    how does the reporting should behave.



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
182
183
# File 'lib/autobuild/reporting.rb', line 144

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

.successObject

Reports a successful build to the user



186
187
188
# File 'lib/autobuild/reporting.rb', line 186

def self.success
    each_reporter(&:success)
end