From c864bf6342f088dabfab305c0e9a7c7f91919f9e Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 8 Sep 2011 10:26:11 -0400 Subject: [PATCH] Log a useful error message when trying to dump and invalid value. --- h5config/config.py | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/h5config/config.py b/h5config/config.py index e8ff023..6f4112f 100644 --- a/h5config/config.py +++ b/h5config/config.py @@ -20,6 +20,8 @@ import copy as _copy +from . import LOG as _LOG + class Setting (object): "A named setting with arbitrart text values." @@ -297,20 +299,25 @@ class Config (dict): for setting in self.settings: name = setting.name value = self[name] - if isinstance(setting, ConfigSetting): - if value is not None: - lines.append(value.dump(help=help, prefix=prefix+' ')) - continue - elif isinstance(setting, ConfigListSetting): - if value: - for config in value: - lines.append( - config.dump(help=help, prefix=prefix+' ')) - continue - value_string = setting.convert_to_text(self[name]) - if help: - help_string = '\t({})'.format(setting.help()) - else: - help_string = '' - lines.append('{}: {}{}'.format(name, value_string, help_string)) + try: + if isinstance(setting, ConfigSetting): + if value is not None: + lines.append(value.dump(help=help, prefix=prefix+' ')) + continue + elif isinstance(setting, ConfigListSetting): + if value: + for config in value: + lines.append( + config.dump(help=help, prefix=prefix+' ')) + continue + value_string = setting.convert_to_text(self[name]) + if help: + help_string = '\t({})'.format(setting.help()) + else: + help_string = '' + lines.append('{}: {}{}'.format( + name, value_string, help_string)) + except Exception: + _LOG.error('could not dump {} ({!r})'.format(name, value)) + raise return '\n'.join(lines) -- 2.26.2