mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Add exception logging on serialize/deserialize exceptions
Since we are reraising an error using our own exception classes, we lose the traceback. This adds exception logging to provide useful information to troubleshoot errors encountered while serializing/deserializing.
This commit is contained in:
parent
c62c855f9c
commit
09458c65cf
@ -11,6 +11,7 @@
|
||||
|
||||
from __future__ import absolute_import
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
import yaml
|
||||
from yaml.constructor import ConstructorError
|
||||
@ -22,6 +23,8 @@ from salt.utils.odict import OrderedDict
|
||||
|
||||
__all__ = ['deserialize', 'serialize', 'available']
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
available = True
|
||||
|
||||
# prefer C bindings over python when available
|
||||
@ -46,14 +49,17 @@ def deserialize(stream_or_string, **options):
|
||||
try:
|
||||
return yaml.load(stream_or_string, **options)
|
||||
except ScannerError as error:
|
||||
log.exception('Error encountered while deserializing')
|
||||
err_type = ERROR_MAP.get(error.problem, 'Unknown yaml render error')
|
||||
line_num = error.problem_mark.line + 1
|
||||
raise DeserializationError(err_type,
|
||||
line_num,
|
||||
error.problem_mark.buffer)
|
||||
except ConstructorError as error:
|
||||
log.exception('Error encountered while deserializing')
|
||||
raise DeserializationError(error)
|
||||
except Exception as error:
|
||||
log.exception('Error encountered while deserializing')
|
||||
raise DeserializationError(error)
|
||||
|
||||
|
||||
@ -74,6 +80,7 @@ def serialize(obj, **options):
|
||||
return response[:-1]
|
||||
return response
|
||||
except Exception as error:
|
||||
log.exception('Error encountered while serializing')
|
||||
raise SerializationError(error)
|
||||
|
||||
|
||||
|
@ -150,14 +150,17 @@ def deserialize(stream_or_string, **options):
|
||||
try:
|
||||
return yaml.load(stream_or_string, **options)
|
||||
except ScannerError as error:
|
||||
log.exception('Error encountered while deserializing')
|
||||
err_type = ERROR_MAP.get(error.problem, 'Unknown yaml render error')
|
||||
line_num = error.problem_mark.line + 1
|
||||
raise DeserializationError(err_type,
|
||||
line_num,
|
||||
error.problem_mark.buffer)
|
||||
except ConstructorError as error:
|
||||
log.exception('Error encountered while deserializing')
|
||||
raise DeserializationError(error)
|
||||
except Exception as error:
|
||||
log.exception('Error encountered while deserializing')
|
||||
raise DeserializationError(error)
|
||||
|
||||
|
||||
@ -178,6 +181,7 @@ def serialize(obj, **options):
|
||||
return response[:-1]
|
||||
return response
|
||||
except Exception as error:
|
||||
log.exception('Error encountered while serializing')
|
||||
raise SerializationError(error)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user