Commit 0fa8cc34 authored by Christof Schulze's avatar Christof Schulze 😎
Browse files

more content in AMMSMLError

parent 88bb473f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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

+31 −1
Original line number Diff line number Diff line
@@ -16,10 +16,40 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Ammsml.  If not, see <http://www.gnu.org/licenses/>.

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):
+0 −0

File moved.