aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/lib/active_job/arguments.rb
diff options
context:
space:
mode:
authorCristian Bica <cristian.bica@gmail.com>2014-08-23 14:19:44 +0300
committerCristian Bica <cristian.bica@gmail.com>2014-08-24 16:01:58 +0300
commit23329d33d45c7388d33c6080820927b96fb34890 (patch)
tree1ca96a6ac5780e1850a355a9b4c3a2e06bf3e92e /activejob/lib/active_job/arguments.rb
parentba1d02d8333372ce55baa2e0d4ccb7d7da56400f (diff)
downloadrails-23329d33d45c7388d33c6080820927b96fb34890.tar.gz
rails-23329d33d45c7388d33c6080820927b96fb34890.tar.bz2
rails-23329d33d45c7388d33c6080820927b96fb34890.zip
Raise ActiveJob::SerializationError when cannot serialize job arguments
Diffstat (limited to 'activejob/lib/active_job/arguments.rb')
-rw-r--r--activejob/lib/active_job/arguments.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/activejob/lib/active_job/arguments.rb b/activejob/lib/active_job/arguments.rb
index 369e716912..ccee4ab35b 100644
--- a/activejob/lib/active_job/arguments.rb
+++ b/activejob/lib/active_job/arguments.rb
@@ -1,4 +1,7 @@
module ActiveJob
+ # Raised when an exception is raised during job arguments deserialization.
+ #
+ # Wraps the original exception raised as +original_exception+.
class DeserializationError < StandardError
attr_reader :original_exception
@@ -9,6 +12,14 @@ module ActiveJob
end
end
+ # Raised when an unsupporter argument type is being set as job argument. We
+ # currently support NilClass, Fixnum, Float, String, TrueClass, FalseClass,
+ # Bignum and object that can be represented as GlobalIDs (ex: Active Record).
+ # Also raised if you set the key for a Hash something else than a string or
+ # a symbol.
+ class SerializationError < ArgumentError
+ end
+
module Arguments
extend self
TYPE_WHITELIST = [ NilClass, Fixnum, Float, String, TrueClass, FalseClass, Bignum ]
@@ -33,7 +44,7 @@ module ActiveJob
when Hash
Hash[ argument.map { |key, value| [ serialize_hash_key(key), serialize_argument(value) ] } ]
else
- raise "Unsupported argument type: #{argument.class.name}"
+ raise SerializationError.new("Unsupported argument type: #{argument.class.name}")
end
end
@@ -55,7 +66,7 @@ module ActiveJob
when String, Symbol
key.to_s
else
- raise "Unsupported hash key type: #{key.class.name}"
+ raise SerializationError.new("Unsupported hash key type: #{key.class.name}")
end
end
end