Skip to content

Commit

Permalink
Include bad job in job validation errors, fixes #4549
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed May 2, 2020
1 parent 756d6cb commit 9dc9d08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changes.md
Expand Up @@ -8,6 +8,7 @@ Unreleased
- Web UI - Dark Mode fixes [#4543, natematykiewicz]
- Ensure `Rack::ContentLength` is loaded as middleware for correct Web UI responses [#4541]
- Avoid exception dumping SSL store in Redis connection logging [#4532]
- Better error messages in Sidekiq::Client [#4549]

6.0.7
---------
Expand Down
14 changes: 9 additions & 5 deletions lib/sidekiq/client.rb
Expand Up @@ -218,16 +218,20 @@ def process_single(worker_class, item)
end
end

def validate(item)
raise(ArgumentError, "Job must be a Hash with 'class' and 'args' keys: `#{item}`") unless item.is_a?(Hash) && item.key?("class") && item.key?("args")
raise(ArgumentError, "Job args must be an Array: `#{item}`") unless item["args"].is_a?(Array)
raise(ArgumentError, "Job class must be either a Class or String representation of the class name: `#{item}`") unless item["class"].is_a?(Class) || item["class"].is_a?(String)
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)
end

def normalize_item(item)
# 6.0.0 push_bulk bug, #4321
# TODO Remove after a while...
item.delete("at") if item.key?("at") && item["at"].nil?

raise(ArgumentError, "Job must be a Hash with 'class' and 'args' keys: { 'class' => SomeWorker, 'args' => ['bob', 1, :foo => 'bar'] }") unless item.is_a?(Hash) && item.key?("class") && item.key?("args")
raise(ArgumentError, "Job args must be an Array") unless item["args"].is_a?(Array)
raise(ArgumentError, "Job class must be either a Class or String representation of the class name") unless item["class"].is_a?(Class) || item["class"].is_a?(String)
raise(ArgumentError, "Job 'at' must be a Numeric timestamp") if item.key?("at") && !item["at"].is_a?(Numeric)
raise(ArgumentError, "Job tags must be an Array") if item["tags"] && !item["tags"].is_a?(Array)
validate(item)
# raise(ArgumentError, "Arguments must be native JSON types, see https://github.com/mperham/sidekiq/wiki/Best-Practices") unless JSON.load(JSON.dump(item['args'])) == item['args']

# merge in the default sidekiq_options for the item's class and/or wrapped element
Expand Down

0 comments on commit 9dc9d08

Please sign in to comment.