Skip to content
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

Don't shadow gem loading errors during autoloading with the inline adapter #1486

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/good_job/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def perform_inline(job, notify: true)
job.advisory_unlock
job.run_callbacks(:perform_unlocked)

raise result.unhandled_error if result.unhandled_error
raise result.unhandled_error if result&.unhandled_error
end
end
end
3 changes: 2 additions & 1 deletion sorbet/rbi/todo.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ module ::WrapperJob; end
module GoodJob::Job::ERROR_EVENT_INTERRUPTED; end
module GoodJob::Job::ERROR_EVENT_RETRIED; end
module Rails::Server; end

module ::AutoloadModule; end
module ::AutoloadModule::Error; end
31 changes: 31 additions & 0 deletions spec/integration/adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,37 @@ def perform
expect(PERFORMED.size).to eq 3
end

describe 'autoloading error' do
around do |example|
File.write("autoload_error.rb", <<~RUBY)
module AutoloadModule
class Error
gem "missing"
end
end
RUBY
example.call
ensure
FileUtils.rm_f("autoload_error.rb")
end

before do
stub_const "AutoloadModule", Module.new
AutoloadModule.autoload :Error, "./autoload_error"
stub_const "TestJob", (Class.new(ActiveJob::Base) do
def perform
AutoloadModule::Error
end
end)
end

it 'raises the correct error' do
expect do
TestJob.perform_later
end.to raise_error(Gem::LoadError, /is not part of the bundle/)
end
end

describe 'immediate retries' do
before do
stub_const "TestJob", (Class.new(ActiveJob::Base) do
Expand Down