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

Support for Rails ActionableError #465

Merged
merged 5 commits into from May 14, 2020

Conversation

connorshea
Copy link
Contributor

@connorshea connorshea commented May 14, 2020

Fixes #443, fixes #455.

This adds support for actionable exceptions in Rails. For example, when a migration needs to be run it'll offer a button that can run the migrations for the user.

Original Actionable Errors PR in Rails: rails/rails#34788

This is what the original PR uses to create the button:

<%= button_to action, ActionDispatch::ActionableExceptions.endpoint, params: {
  error: exception.class.name,
  action: action,
  location: request.path
} %>

ActionView Helpers aren't loaded in the better errors view, so I instead opted to recreate the form myself using mostly the same variables. It's not a beautiful solution, but it works and I'm not sure if there's really a better way to work around that problem.

The button looks like this:

Screen Shot 2020-05-13 at 7 49 43 PM

It's hidden from the user behind the overflow, so it only shows up on hover. We could probably make it more obvious, but I'm not sure how exactly we should do it.

Reproduction steps:

  • Add my fork of the better_errors gem to your Rails app. (gem 'better_errors', git: 'https://github.com/connorshea/better_errors.git', branch: 'actionable-errors')
  • Run a Rails app on at least 6.0 with rails s or whatever your equivalent is for your app.
  • Run rails g migration AddFooToBar in your terminal
  • Load any page in your app
  • See a PendingMigrationError
  • See that it now has a button to run the migrations.
  • Click the button.
  • See the migration has now been run.

We'll also want to make sure better_errors still works on versions before Rails 6 that don't have actionable errors, and I guess add a test to better_errors for this behavior?

This adds support for actionable exceptions in Rails. For example, when
a migration needs to be run it'll offer a button that can run
the migrations for the user.
@connorshea connorshea changed the title Add a button the error page if the error is actionable. Add a button to the error page if the error is actionable. May 14, 2020
@ethan-dowler
Copy link

i will check this out when i have some time!

and include an element around the action forms, and move the use of ActionDispatch out of the template.
These look good when output to the console, but double-newlines make the exception harder to read in BE and push any action buttons further down.
This is purely for BE development.
@RobinDaugherty
Copy link
Member

Thank you @connorshea! I've made some changes to support non-Rails scenarios, I've added specs to cover the functionality, and I made some slight changes to the layout. Here's what it looks like now:

Screen Shot 2020-05-14 at 10 45 34

I'll merge this once as soon as the specs pass.

@connorshea
Copy link
Contributor Author

🎉 great, thanks @RobinDaugherty!

Co-authored-by: Connor Shea <connor.james.shea@gmail.com>
@RobinDaugherty RobinDaugherty changed the title Add a button to the error page if the error is actionable. Support for Rails ActionableError May 14, 2020
@RobinDaugherty RobinDaugherty added this to the v2.8 milestone May 14, 2020
@RobinDaugherty RobinDaugherty merged commit 448c9f2 into BetterErrors:master May 14, 2020
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

Successfully merging this pull request may close these issues.

Add Run pending migrations button Question: Any plan to support ActionableError?
3 participants