From 0fa8cc34f968582348cbbfe65ae576c520686855 Mon Sep 17 00:00:00 2001 From: Christof Schulze Date: Wed, 16 Oct 2019 21:40:08 +0200 Subject: [PATCH] more content in AMMSMLError --- color.py | 2 +- errors.py | 32 ++++++++++++++++++++++++++++- parseing_yaml.py => parsing_yaml.py | 0 3 files changed, 32 insertions(+), 2 deletions(-) rename parseing_yaml.py => parsing_yaml.py (100%) diff --git a/color.py b/color.py index 29c31c2..537f464 100644 --- a/color.py +++ b/color.py @@ -18,8 +18,8 @@ import sys import re -from ammsml.config import constants as C +from ammsml.config import constants as C IS_COLOR: bool = True diff --git a/errors.py b/errors.py index 916d54d..4541405 100644 --- a/errors.py +++ b/errors.py @@ -16,10 +16,40 @@ # You should have received a copy of the GNU Lesser General Public License # along with Ammsml. If not, see . +from ammsml.utils.parsing import to_text +from ammsml.utils.parsing_yaml import AMMSMLBaseYAMLObject + class AMMSMLError(Exception): + """ + This is the base class for all errors raised from Ammsml code, + and can be instantiated with two optional parameters beyond the + error message to control whether detailed information is displayed + when the error occurred while parsing a data file of some kind. - pass + Usage: + raise AMMSMLError('some message here', obj=obj, show_content=True) + + Where "obj" is some subclass of ammsml.utils.parsing.yaml.objects.AMMSMLBaseYAMLObject, + which should be returned by the DataLoader() class. + + Something like this, TODO to be improved + """ + + def __init__(self, message="", obj=None, show_content=True, suppress_extended_error=False, orig_exc=None): + super(AMMSMLError, self).__init__(message) + + self._obj = obj + self._show_content = show_content + + if obj and isinstance(obj, AMMSMLBaseYAMLObject): + extended_error = self._get_extended_error() + if extended_error and not suppress_extended_error: + self.message = '%s\n\n%s' % (to_text(message), to_text(extended_error)) + else: + self.message = '%s' % to_text(message) + else: + self.message = '%s' % to_text(message) class AMMSMLParserError(AMMSMLError): diff --git a/parseing_yaml.py b/parsing_yaml.py similarity index 100% rename from parseing_yaml.py rename to parsing_yaml.py -- GitLab