-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add interface to require dead_end without core_ext #119
Conversation
ef9f844
to
1f2541a
Compare
Currently `dead_end` works by monkey patching `require` and friends. If someone wants to programmatically execute dead_end manually via `DeadEnd.handle_error` without monkey patches they can now do that by setting the environment variable `DISABLE_DEAD_END_CORE_EXT=1`.
1f2541a
to
56d2bf0
Compare
Instead of an environment variable, which people could forget to set in certain environments (laptop, dev box, CI, QA, production, etc.), what do you think about factoring most of the contents of require_relative 'dead_end/api'
require_relative 'dead_end/core_ext' ? That wouldn't break any existing users, and would also allow people who want to avoid the monkey patch to just do require 'dead_end/api' and never have to worry about making sure the environment variable is set. This is similar to how some other gems work. Curious what you think! |
Previously I had all the code in |
Because setting environment variables on systems may be difficult or inconsistent we are moving the API to be require based. Now anyone who wants to use dead_end without mutating `require` can do so via requiring `dead_end/api`.
5871901
to
dc18d1a
Compare
Updated the PR to move to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm thanks!
lib/dead_end/api.rb
Outdated
|
||
# DeadEnd.handle_error [Public] | ||
# | ||
# Takes an exception from a syntax error, uses that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the interface specifically that callers must pass a SyntaxError
exception? I see that you don't mention that in the rescue
line below, though you do mention it in the lib/dead_end/core_ext.rb
file.
If it's intended for that requirement to be explicit, do you want to check that in handle_error
like
raise TypeError.new("must pass a SyntaxError") unless e.is_a?(SyntaxError)
(I find that it's usually more forgiving to start with a narrow API and widen it, but it's up to you.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little torn. I agree that being stricter is better. Rather than raising a new error though I decided to warn and re-raise the original error which is a pattern I have in other places.
Take a look and let me know what you think. Also as a heads up, if you all haven't run into it yet require_relative
monkeypatching is broken with Ruby 3.1 and needs to be fixed Shopify/bootsnap@0d64e7e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
works for me.
Co-authored-by: Jake Zimmerman <zimmerman.jake@gmail.com>
As suggested in #119 (comment) we are now explicitly checking the type of the incoming error. Rather than raise a new error, I've chosen to emit a warning and re-raise the original error. This is a similar pattern to the case where we are not able to detect the filename from the error message. The goal is to provide visibility into the source of the behavior, but to break as few expectations as possible. The `DeadEnd.handle_error` should (ideally) never raise an error to the end user. The purpose of the library is to provide progressive error enhancement. If it fails it means we cannot make a better error, so therefore we should warn (so the user can fix or report the problem) and then fall back to the original error. I also added a test for the failure error condition where the filename cannot be pulled out of the SyntaxError message which was added in #114.
As suggested in #119 (comment) we are now explicitly checking the type of the incoming error. Rather than raise a new error, I've chosen to emit a warning and re-raise the original error. This is a similar pattern to the case where we are not able to detect the filename from the error message. The goal is to provide visibility into the source of the behavior, but to break as few expectations as possible. The `DeadEnd.handle_error` should (ideally) never raise an error to the end user. The purpose of the library is to provide progressive error enhancement. If it fails it means we cannot make a better error, so therefore we should warn (so the user can fix or report the problem) and then fall back to the original error. I also added a test for the failure error condition where the filename cannot be pulled out of the SyntaxError message which was added in #114.
34d1dde
to
0b40746
Compare
DeadEnd 3.1.0 is released with this change 🎉 🎉 🎉 Thanks for all the feedback ❤️ |
Currently
dead_end
works by monkey patchingrequire
and friends.If someone wants to programmatically execute dead_end manually viaDeadEnd.handle_error
without monkey patches they can now do that by setting the environment variableDISABLE_DEAD_END_CORE_EXT=1
.If someone wants to programmatically execute dead_end manually via
DeadEnd.handle_error
without monkey patches they can now do that by requiringdead_end/api
.I'm specifically interested in feedback around interfaces as they're harder to change after they're adopted.
DeadEnd.handle_error
sound weird or confusing?