diff options
author | Chad Smith <chad.smith@canonical.com> | 2018-05-23 15:56:16 -0400 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2018-05-23 15:56:16 -0400 |
commit | 3b28bdc616f3e7f4d6b419629dc7b9efc3ae8d1e (patch) | |
tree | b0a5d6f097c07ec693b3ff95e6a791955c6302f0 /cloudinit/util.py | |
parent | aa4eeb80839382117e1813e396dc53aa634fd7ba (diff) | |
download | vyos-cloud-init-3b28bdc616f3e7f4d6b419629dc7b9efc3ae8d1e.tar.gz vyos-cloud-init-3b28bdc616f3e7f4d6b419629dc7b9efc3ae8d1e.zip |
yaml_load/schema: Add invalid line and column nums to error message
Yaml tracebacks are generally hard to read for average users. Add a bit of
logic to util.yaml_load and schema validation to look for
YAMLError.context_marker or problem_marker line and column counts.
No longer log the full exceeption traceback from the yaml_load error,
instead just LOG.warning for the specific error and point to the offending
line and column where the problem exists.
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r-- | cloudinit/util.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index 653ed6ea..c0473b8c 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -874,8 +874,20 @@ def load_yaml(blob, default=None, allowed=(dict,)): " but got %s instead") % (allowed, type_utils.obj_name(converted))) loaded = converted - except (yaml.YAMLError, TypeError, ValueError): - logexc(LOG, "Failed loading yaml blob") + except (yaml.YAMLError, TypeError, ValueError) as e: + msg = 'Failed loading yaml blob' + mark = None + if hasattr(e, 'context_mark') and getattr(e, 'context_mark'): + mark = getattr(e, 'context_mark') + elif hasattr(e, 'problem_mark') and getattr(e, 'problem_mark'): + mark = getattr(e, 'problem_mark') + if mark: + msg += ( + '. Invalid format at line {line} column {col}: "{err}"'.format( + line=mark.line + 1, col=mark.column + 1, err=e)) + else: + msg += '. {err}'.format(err=e) + LOG.warning(msg) return loaded |