In the Rails::Command::RakeCommand
class, the call to rake.standard_exception_handling
delegates exception handling during rake.top_level
execution to Rake itself.
In our team, we run Rake tasks via Cron Jobs. In production, when unexpected exceptions occur inside a task, we need to send error reports to monitoring tools or output structured logs.
Since Rails wraps the Rake command, I think it might make sense to also proxy exception handling.
Here’s an example of what such an implementation could look like:
rake.standard_exception_handling do
begin
rake.top_level
rescue Exception => ex
ActiveSupport.error_reporter.report(ex, source: "rails.rake")
raise ex
end
end
I would like to ask for opinions on:
-
Has this kind of issue been discussed before?
-
Would adding such a feature be acceptable?
If it seems acceptable, I’d be happy to open a PR.