diff --git a/color.py b/color.py index 29c31c22d1e772fa379c6e840d8cfb1326d6ae06..537f46427a2a82406e1576c92a992c35db5452f5 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 916d54d74b1e4d053aee9717f5b9c967c161b27e..4541405c253ca16e602f0438f682705a19660179 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