-
Notifications
You must be signed in to change notification settings - Fork 3
/
relation_errors.py
41 lines (34 loc) · 1.48 KB
/
relation_errors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""This module provides the errors for the relation module."""
class ExpectedOneError(Exception):
"""This exception is raised when get count differs from 1."""
def __init__(self, relation, count):
self.rel = relation
self.count = count
self.plural = '' if count == 0 else 's'
Exception.__init__(self, f'Expected 1, got {self.count} tuple{self.plural}')
class UnknownAttributeError(Exception):
"""Unknown attribute error"""
def __init__(self, msg):
super().__init__(f"ERROR! Unknown attribute: {msg}.")
class IsFrozenError(Exception):
"""Class is frozen"""
def __init__(self, cls, msg):
super().__init__(
f"ERROR! The class {cls} is forzen.\n"
f"Use ho_unfreeze to add the '{msg}' attribute to it.")
class DuplicateAttributeError(Exception):
"""Attempt to setattr to an already existing attribute."""
class NotASingletonError(Exception):
"""The constraint do not define a singleton.
Raised from ExpectedOneError (err).
"""
def __init__(self, err):
Exception.__init__(self, f'Not a singleton. Got {err.count} tuple{err.plural}')
class WrongFkeyError(Exception):
"Raised when Fkeys contains a wrong name"
def __init__(self, cls, value):
fkeys_list = "\n".join([f" - {fkey}" for fkey in cls._ho_fkeys.keys()])
err = f"Can't find '{value}'!\n" \
f"List of keys for {cls.__class__.__name__}:\n" \
f"{fkeys_list}"
super().__init__(err)