mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Surface exact job class name in complex argument error message (#5235)
* Surface exact job class name in complex argument error message * Update job_util.rb * Update param for ActiveJob arg serialization failure Co-authored-by: Mike Perham <mperham@gmail.com>
This commit is contained in:
parent
261368db6a
commit
10598b5206
2 changed files with 25 additions and 3 deletions
|
@ -13,15 +13,16 @@ module Sidekiq
|
|||
raise(ArgumentError, "Job 'at' must be a Numeric timestamp: `#{item}`") if item.key?("at") && !item["at"].is_a?(Numeric)
|
||||
raise(ArgumentError, "Job tags must be an Array: `#{item}`") if item["tags"] && !item["tags"].is_a?(Array)
|
||||
|
||||
job_class = item["wrapped"] || item["class"]
|
||||
if Sidekiq.options[:on_complex_arguments] == :raise
|
||||
msg = <<~EOM
|
||||
Job arguments to #{item["class"]} must be native JSON types, see https://github.com/mperham/sidekiq/wiki/Best-Practices.
|
||||
Job arguments to #{job_class} must be native JSON types, see https://github.com/mperham/sidekiq/wiki/Best-Practices.
|
||||
To disable this error, remove `Sidekiq.strict_args!` from your initializer.
|
||||
EOM
|
||||
raise(ArgumentError, msg) unless json_safe?(item)
|
||||
elsif Sidekiq.options[:on_complex_arguments] == :warn
|
||||
Sidekiq.logger.warn <<~EOM unless json_safe?(item)
|
||||
Job arguments to #{item["class"]} do not serialize to JSON safely. This will raise an error in
|
||||
Job arguments to #{job_class} do not serialize to JSON safely. This will raise an error in
|
||||
Sidekiq 7.0. See https://github.com/mperham/sidekiq/wiki/Best-Practices or raise an error today
|
||||
by calling `Sidekiq.strict_args!` during Sidekiq initialization.
|
||||
EOM
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
require_relative "helper"
|
||||
require "sidekiq/api"
|
||||
require "sidekiq/rails"
|
||||
|
||||
describe Sidekiq::Client do
|
||||
describe "errors" do
|
||||
|
@ -220,7 +221,7 @@ describe Sidekiq::Client do
|
|||
|
||||
describe "worker that takes deep, nested structures" do
|
||||
it "raises an error on JSON-unfriendly structures" do
|
||||
assert_raises ArgumentError do
|
||||
error = assert_raises ArgumentError do
|
||||
InterestingWorker.perform_async(
|
||||
{
|
||||
"foo" => [:a, :b, :c],
|
||||
|
@ -228,6 +229,26 @@ describe Sidekiq::Client do
|
|||
}
|
||||
)
|
||||
end
|
||||
assert_match /Job arguments to InterestingWorker/, error.message
|
||||
end
|
||||
end
|
||||
|
||||
describe 'ActiveJob with non-native json types' do
|
||||
before do
|
||||
ActiveJob::Base.queue_adapter = :sidekiq
|
||||
ActiveJob::Base.logger = nil
|
||||
end
|
||||
|
||||
class TestActiveJob < ActiveJob::Base
|
||||
def perform(arg)
|
||||
end
|
||||
end
|
||||
|
||||
it 'raises error with correct class name' do
|
||||
error = assert_raises ArgumentError do
|
||||
TestActiveJob.perform_later(1.1212.to_d)
|
||||
end
|
||||
assert_match /Job arguments to TestActiveJob/, error.message
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue