Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Report all failures #9

Open
greena13 opened this issue Jun 17, 2021 · 2 comments
Open

Feature Request: Report all failures #9

greena13 opened this issue Jun 17, 2021 · 2 comments

Comments

@greena13
Copy link

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.

@AxelTheGerman
Copy link

AxelTheGerman commented Oct 13, 2023

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
Copy link

AxelTheGerman commented Oct 13, 2023

Here the code change but we need to either ship a breaking change or work around it somehow AxelTheGerman@2741a69

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants