Auto-repair logic for health checks that failed.
This module handles running fix functions for checks that returned an error status, providing detailed reporting of what was applied, failed, or skipped.
Summary
Functions
Runs fixes for all checks that have an error status.
Runs fixes for a single check by ID.
Validates that a fix function has the correct arity.
Functions
@spec fix(Botica.Types.config(), [Botica.Types.result()]) :: {:ok, Botica.Types.fix_report()} | {:error, String.t()}
Runs fixes for all checks that have an error status.
Returns a detailed report of what was applied, failed, or skipped.
Examples
iex> config = %{
...> app_name: "test",
...> checks: [
...> %{
...> id: :fail1,
...> name: "Fail 1",
...> check: fn -> {:error, "problem"} end,
...> fix: fn -> {:ok, "fixed!"} end
...> },
...> %{
...> id: :fail2,
...> name: "Fail 2",
...> check: fn -> {:error, "another problem"} end,
...> fix: fn -> {:error, "can't fix"} end
...> },
...> %{
...> id: :ok,
...> name: "OK",
...> check: fn -> {:ok, "good"} end,
...> fix: fn -> :skipped end
...> }
...> ]
...> }
iex> {:ok, results} = Botica.Doctor.run(config)
iex> report = Botica.Repair.Fixer.fix(config, results)
iex> report.applied
[:fail1]
iex> report.failed
[{:fail2, "can't fix"}]
iex> report.skipped
[:ok]
@spec fix_one(Botica.Types.config(), Botica.Types.check_id()) :: {:ok, :applied | :failed | :skipped} | {:error, String.t()}
Runs fixes for a single check by ID.
Examples
iex> config = %{
...> app_name: "test",
...> checks: [
...> %{
...> id: :my_check,
...> name: "My Check",
...> check: fn -> {:error, "problem"} end,
...> fix: fn -> {:ok, "fixed!"} end
...> }
...> ]
...> }
iex> Botica.Repair.Fixer.fix_one(config, :my_check)
{:ok, :applied}
Validates that a fix function has the correct arity.
Examples
iex> Botica.Repair.Fixer.valid_fix?(fn -> :ok end)
true
iex> Botica.Repair.Fixer.valid_fix?(fn _ -> :ok end)
false
iex> Botica.Repair.Fixer.valid_fix?(nil)
false