-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Raise a meaningful error if ActiveStorage::Current.host is blank #41996
Raise a meaningful error if ActiveStorage::Current.host is blank #41996
Conversation
aab8a35
to
db7767e
Compare
db7767e
to
4f30eaf
Compare
@@ -124,6 +124,10 @@ def generate_url(key, expires_in:, filename:, content_type:, disposition:) | |||
purpose: :blob_key | |||
) | |||
|
|||
if current_host.blank? | |||
raise "Cannot generate URL for #{filename} using Disk service, please set ActiveStorage::Current.host." |
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 think this should use argument error instead:
raise "Cannot generate URL for #{filename} using Disk service, please set ActiveStorage::Current.host." | |
raise ArgumentError, "Cannot generate URL for #{filename} using Disk service, please set ActiveStorage::Current.host." |
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.
@eileencodes thanks for the review. Your suggestion makes perfect sense to me, I've updated the PR accordingly. 🙂
4f30eaf
to
10f2a9d
Compare
It's very hard to understand what happens with the following exception URI::InvalidURIError: bad URI(is not URI?): nil that is raised when trying to generate a URL for Disk service without setting the ActiveStorage::Current.host first. This can happen when the ActiveStorage::SetCurrent is not included in a controller, or when testing URL generation outside of the controllers layer (eg. testing URL generation in a model). Co-authored-by: elia <elia@schito.me> Co-authored-by: filippo <dev@mailvore.com>
10f2a9d
to
f971a3f
Compare
Thanks for the PR and congrats on your first Rails commit 💖 |
Summary
It's very hard to understand what happens with the following exception
that is raised when trying to generate a URL for Disk service without setting the
ActiveStorage::Current.host
first.This can happen when the
ActiveStorage::SetCurrent
is not included in a controller, or when testing URL generation outside of the controllers layer (eg. testing URL generation in a model).cc @elia @filippoliverani