health_bit icon indicating copy to clipboard operation
health_bit copied to clipboard

Feature Request: Report all failures

Open greena13 opened this issue 4 years ago • 2 comments

HealthBit version: 0.1.8

Currently only the first failed check is returned. It would be nice to have an option to continue beyond the first failed check and report all failures.

greena13 avatar Jun 17 '21 16:06 greena13

Same here I think its crucial! Not a lot of work but would be a breaking change for custom formatter as they now would receive an array of errors to format instead of one.

This monkey patch does it for me though:

module HealthBit
  def check(env)
    results = checks.map do |check|
      check.call(env)
    end

    results.compact
  end

  def rack(this = self)
    @rack ||= Rack::Builder.new do
      run ->(env) do
        errors = this.check(env)
        if errors.any?
          [
            this.formatter.code_failure(errors, env, this),
            this.formatter.headers_failure(errors, env, this),
            [this.formatter.format_failure(errors, env, this)]
          ]
        else
          [
            this.formatter.code_success(env, this),
            this.formatter.headers_success(env, this),
            [this.formatter.format_success(errors, env, this)]
          ]
        end
      end
    end
  end

  class Formatter
    # @param errors [HealthBit::CheckError]
    # @param env Hash
    # @param health_bit HealthBit
    def format_failure(errors, env, health_bit)
      format = health_bit.show_backtrace ? CheckError::FORMAT_FULL : CheckError::FORMAT_SHORT
      errors.map { |error| error.to_s(format) }.join("\n")
    end
  end
end

AxelTheGerman avatar Oct 13 '23 00:10 AxelTheGerman

Here the code change but we need to either ship a breaking change or work around it somehow https://github.com/AxelTheGerman/health_bit/commit/2741a69dfbe8e4214a0096dd3ebe684e9be89e16

AxelTheGerman avatar Oct 13 '23 00:10 AxelTheGerman