Artur-Sulej / excellent_migrations

An Elixir tool for checking safety of database migrations.
MIT License
232 stars 25 forks source link

Provide guidance links in mix tasks' `Logger.error` output #26

Open vanderhoop opened 1 year ago

vanderhoop commented 1 year ago

We just added excellent_migrations to a large repository with many newish Elixir developers contributing to it. I noticed that the current Logger.error output can be somewhat cryptic, and it isn't clear what the next steps are or where the errors originate.

This pull request adds links to the README's 'Checks' and 'Assuring Safety' section to the error output of the mix tasks.

I haven't yet determined how to do the same for the credo check, but I'll happily add it if this first PR is welcomed.

Before

Screen Shot 2023-03-08 at 2 58 27 PM

After

Screen Shot 2023-03-08 at 3 20 26 PM

Artur-Sulej commented 1 year ago

Thanks for the PR and using the lib! I like your solution, because it quickly adds value and I'll be happy to merge your PR after testing.

I was thinking about introducing something similar myself. My idea was to add README links to specific dangers that were detected. Additionally these links would point to README from a lib version that is used.

For example column_renamed check is triggered when using excellent_migrations 0.1.6 – and the message would contain this link: https://github.com/Artur-Sulej/excellent_migrations/blob/v0.1.6/README.md#renaming-a-column With this approach users are pointed to the right place in docs and links would always work even if changed in newer versions.

After adjusting links to match check names, links could be built with this logic:

def build_link(current_version, anchor) do
  anchor =
    check
    |> Atom.to_astring()
    |> String.replace("_", "-")

  "#{@base_url}/blob/v#{current_version}/README.md##{anchor}"
end

Anyway, that could be done in the future.

vanderhoop commented 1 year ago

After adjusting links to match check names, links could be built with this logic:

def build_link(current_version, anchor) do
  anchor =
    check
    |> Atom.to_astring()
    |> String.replace("_", "-")

  "#{@base_url}/blob/v#{current_version}/README.md##{anchor}"
end

I actually started down a path of trying to build out links and aborted due to not knowing if you'd be interested in a bigger change, but I hadn't considered tying the links to the particular release tag to avoid brittleness. That's 💯

Happy to take on the subsequent change once this first one goes in.

vanderhoop commented 3 months ago

@Artur-Sulej I'm curious how you're feeling about this. I just got around to auditing my dependencies on a side project, and realized my fork was behind origin. These warnings have aided me personally :)