Due to the default behavior of Python's json.loads(), invalid JSON can be passed to the OpenWhisk Controller when firing a trigger. This occurs when constants NaN, Infinity, -Infinity are present in the JSON consumed from Kafka. Such an event results in a 400 HTTP error from the trigger invocation request. When a 400 status code is returned to the Kafka provider, the user's corresponding trigger is automatically disabled.
Providing a parse_constant function that throws an error allows us to fail when NaN is present.
json.loads('{"a":[NaN]}', parse_constant=parseJSONConstant)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 351, in loads
return cls(encoding=encoding, **kw).decode(s)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 382, in raw_decode
obj, end = self.scan_once(s, idx)
File "<stdin>", line 3, in parseJSONConstant
ValueError: Invalid JSON detected
Due to the default behavior of Python's
json.loads()
, invalid JSON can be passed to the OpenWhisk Controller when firing a trigger. This occurs when constantsNaN
,Infinity
,-Infinity
are present in the JSON consumed from Kafka. Such an event results in a400
HTTP error from the trigger invocation request. When a400
status code is returned to the Kafka provider, the user's corresponding trigger is automatically disabled.Showing
json.loads
parsingNaN
without a failure.Providing a
parse_constant
function that throws an error allows us to fail whenNaN
is present.