-
Notifications
You must be signed in to change notification settings - Fork 11
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
name clash with halite #78
Comments
Did it cause any troubles? Halite's Anyway, I think that Onyx should not monkey-patch |
to reproduce: require "onyx/http"
require "halite"
Onyx::HTTP.get "/" do |env|
env.response << "Hello, Onyx!"
end
Onyx::HTTP.get "/proxy" do |env|
r = Halite.get("http://localhost:5000")
env.response << r.body
end
Onyx::HTTP.listen when compiling:
It seems the |
Some wild guesses from me:
P.S: You can use |
Changing require order doesn't work. Monkey-patching works, but have to define it as nil-able: module Halite
module Exception
class APIError < ResponseError
getter status_message : String | Nil
end
end
end Still, this feels hacky. Should I report this to halite? P.S. Nice trick about the |
No, I don't think so. It's Onyx's issue. |
It's not that simple. Onyx rescues all This is the extension used in Onyx: class Exception
# The status message for this error. Returns its class name decorated as
# an HTTP status message, for example `"User Not Found"` for
# `MyEndpoint::UserNotFound` error.
def status_message
{{@type.name.split("::").last.underscore.split("_").map(&.capitalize).join(" ")}}
end
end This way the exception's formatted name is baked into the binary. There are plenty of places where It seems like a good idea to rename the method to |
Another option would be wrapping all rescued exceptions into a generic class: class Onyx::HTTP::Exception(T)
# The status message for this exception. Returns `T` class name decorated as
# an HTTP status message, for example `"User Not Found"` for
# `Onyx::HTTP::Exception(MyEndpoint::UserNotFound)`.
def status_message
{{T.name.split("::").last.underscore.split("_").map(&.capitalize).join(" ")}}
end
end
class HTTP::Server::Response
# A rescued error which is likely to be put into the response output.
property error : Onyx::HTTP::Exception?
def reset
previous_def
@error = nil
end
end |
I think a scoped (within Onyx's namespace) exception class is better, so that it doesn't interfere with other classes with a same name. |
both defined a
status_message
:How is this usually resolved in Crystal?
The text was updated successfully, but these errors were encountered: