Update exception handling based on discussions.
ValueErrors identified as associated with logging and are classed as a failure rather than expected behavior.
This commit is contained in:
parent
1228ca6243
commit
a37fac864f
|
@ -30,8 +30,7 @@ proc copyState(state: BeaconState, output: ptr byte,
|
||||||
try:
|
try:
|
||||||
resultState = SSZ.encode(state)
|
resultState = SSZ.encode(state)
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
# TODO is an IOError indicative of a bug? e.g. any state passed to it after processing should be valid and serializable?
|
# Shouldn't occur as the writer isn't a file
|
||||||
# How can this raise an IOError (as the writer isn't to a file?)?
|
|
||||||
raise newException(FuzzCrashError, "Unexpected failure to serialize.", e)
|
raise newException(FuzzCrashError, "Unexpected failure to serialize.", e)
|
||||||
|
|
||||||
if unlikely(resultState.len.uint > output_size[]):
|
if unlikely(resultState.len.uint > output_size[]):
|
||||||
|
@ -64,11 +63,11 @@ proc nfuzz_attestation(input: openArray[byte], output: ptr byte,
|
||||||
try:
|
try:
|
||||||
result = process_attestation(data.state, data.attestation,
|
result = process_attestation(data.state, data.attestation,
|
||||||
{skipValidation}, cache)
|
{skipValidation}, cache)
|
||||||
except ValueError:
|
except ValueError as e:
|
||||||
# TODO is a ValueError indicative of correct or incorrect processing code?
|
# These exceptions are expected to be raised by chronicles logging:
|
||||||
# If correct (but given invalid input), we should return false
|
# See status-im/nim-chronicles#60
|
||||||
# If incorrect, we should allow it to crash
|
# TODO remove this when resolved
|
||||||
result = false
|
raise newException(FuzzCrashError, "Unexpected (logging?) error in attestation processing", e)
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
result = copyState(data.state, output, output_size)
|
result = copyState(data.state, output, output_size)
|
||||||
|
@ -88,11 +87,9 @@ proc nfuzz_attester_slashing(input: openArray[byte], output: ptr byte,
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = process_attester_slashing(data.state, data.attesterSlashing, cache)
|
result = process_attester_slashing(data.state, data.attesterSlashing, cache)
|
||||||
except ValueError:
|
except ValueError as e:
|
||||||
# TODO is a ValueError indicative of correct or incorrect processing code?
|
# TODO remove when status-im/nim-chronicles#60 is resolved
|
||||||
# If correct (but given invalid input), we should return false
|
raise newException(FuzzCrashError, "Unexpected (logging?) error in attester slashing", e)
|
||||||
# If incorrect, we should allow it to crash
|
|
||||||
result = false
|
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
result = copyState(data.state, output, output_size)
|
result = copyState(data.state, output, output_size)
|
||||||
|
@ -110,18 +107,14 @@ proc nfuzz_block(input: openArray[byte], output: ptr byte,
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = state_transition(data.state, data.beaconBlock, {})
|
result = state_transition(data.state, data.beaconBlock, {})
|
||||||
except IOError as e:
|
except IOError, ValueError:
|
||||||
# TODO why an IOError?
|
# TODO remove when status-im/nim-chronicles#60 is resolved
|
||||||
raise newException(FuzzCrashError, "Unexpected IOError in state transition", e)
|
let e = getCurrentException()
|
||||||
|
raise newException(FuzzCrashError, "Unexpected (logging?) error in state transition", e)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# TODO why an Exception?
|
# TODO why an Exception?
|
||||||
# Lots of vendor code looks like it might raise a bare exception type
|
# Lots of vendor code looks like it might raise a bare exception type
|
||||||
raise newException(FuzzCrashError, "Unexpected IOError in state transition", e)
|
raise newException(FuzzCrashError, "Unexpected Exception in state transition", e)
|
||||||
except ValueError:
|
|
||||||
# TODO is a ValueError indicative of correct or incorrect processing code?
|
|
||||||
# If correct (but given invalid input), we should return false
|
|
||||||
# If incorrect, we should allow it to crash
|
|
||||||
result = false
|
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
result = copyState(data.state, output, output_size)
|
result = copyState(data.state, output, output_size)
|
||||||
|
@ -142,14 +135,10 @@ proc nfuzz_block_header(input: openArray[byte], output: ptr byte,
|
||||||
try:
|
try:
|
||||||
# TODO disable bls
|
# TODO disable bls
|
||||||
result = process_block_header(data.state, data.beaconBlock, {}, cache)
|
result = process_block_header(data.state, data.beaconBlock, {}, cache)
|
||||||
except IOError as e:
|
except IOError, ValueError:
|
||||||
# TODO why an IOError? - is this expected/should we return false?
|
let e = getCurrentException()
|
||||||
|
# TODO remove when status-im/nim-chronicles#60 is resolved
|
||||||
raise newException(FuzzCrashError, "Unexpected IOError in block header processing", e)
|
raise newException(FuzzCrashError, "Unexpected IOError in block header processing", e)
|
||||||
except ValueError:
|
|
||||||
# TODO is a ValueError indicative of correct or incorrect processing code?
|
|
||||||
# If correct (but given invalid input), we should return false
|
|
||||||
# If incorrect, we should allow it to crash
|
|
||||||
result = false
|
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
result = copyState(data.state, output, output_size)
|
result = copyState(data.state, output, output_size)
|
||||||
|
|
Loading…
Reference in New Issue