-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Exceptions from within promises #566
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
Comments
Oh, interesting. I guess that's a flaw in the runtime design. Middleware only wraps I guess the best "fix" is to introduce an error handling plugin like MySchema = GraphQL::Schema.define do
use GraphQL::Rescues
end which will wrap both eager- and lazy-loading with error handling. (In my opinion, the real best case would be to avoid raising errors altogether 😆 ) |
You can catch the error and return a def promise(&_blk)
Rails.application.executor.wrap do
Concurrent::Promise
.execute { Rails.application.executor.wrap { yield } }
.catch { |e| handle_error(e) }
end
end
def handle_error(e)
Rails.logger.error(e)
Rails.logger.error(e.backtrace.join("\n"))
GraphQL::ExecutionError.new(e.message)
end |
I just merged some new error handling for the interpreter that properly catches errors in promises: #2458 If you give it a try and have a problem, please open a new issue! |
It looks like the
RescueMiddleware
does not handle exceptions coming from within promises.When we hit a
ActiveRecord::RecordNotFound
in a non-lazy resolver then the middleware takes care of it, but when we hit that same exception inside a lazy promise resolver, then the error makes it's way all the way out to the rails controller.The text was updated successfully, but these errors were encountered: