Add ShouldNeverHappen exception

This commit is contained in:
Joscha 2019-06-07 17:30:50 +00:00
parent a9ddf27525
commit d8ee20c402
4 changed files with 16 additions and 6 deletions

View file

@ -7,6 +7,7 @@ from .cursor_rendering import *
from .cursor_tree_widget import *
from .element import *
from .element_supply import *
from .exceptions import *
from .markup import *
from .rendered_element_cache import *
@ -19,5 +20,6 @@ __all__ += cursor_rendering.__all__
__all__ += cursor_tree_widget.__all__
__all__ += element.__all__
__all__ += element_supply.__all__
__all__ += exceptions.__all__
__all__ += markup.__all__
__all__ += rendered_element_cache.__all__

View file

@ -6,6 +6,7 @@ from typing import Generic, List, Optional, Tuple, TypeVar
from .attributed_lines import AttributedLines
from .element import Element, Id, Message, RenderedElement, RenderedMessage
from .element_supply import ElementSupply
from .exceptions import ShouldNeverHappen
from .markup import AT, AttributedText, Attributes
from .rendered_element_cache import RenderedElementCache
@ -408,11 +409,9 @@ class CursorTreeRenderer(Generic[E]):
return 0, middle_index
if middle_index < self.lines.upper_offset:
raise Exception()
attrs, _ = lines[0]
index = self.lines.upper_offset
elif middle_index > self.lines.lower_offset:
raise Exception()
attrs, _ = lines[-1]
index = self.lines.lower_offset
else:
@ -535,7 +534,7 @@ class CursorTreeRenderer(Generic[E]):
message = self._cache.get(mid)
if message is None:
raise Exception() # TODO use better exception
raise ShouldNeverHappen(1)
height += len(message.lines)
@ -553,7 +552,7 @@ class CursorTreeRenderer(Generic[E]):
below_new = self._element_id_below_cursor(new_cursor_id)
if above_old is None:
raise Exception() # TODO use better exception
raise ShouldNeverHappen(2)
# Moving horizontally at the bottom of the supply
if below_new is None:
@ -579,7 +578,7 @@ class CursorTreeRenderer(Generic[E]):
above_new = self._element_id_above_cursor(new_cursor_id)
if above_new is None:
raise Exception() # TODO use better exception
raise ShouldNeverHappen(3)
# Moving horizontally at the bottom of the supply
if below_old is None:

View file

@ -1,4 +1,10 @@
__all__ = ["MessageSupplyException"]
__all__ = ["MessageSupplyException", "ShouldNeverHappen"]
class MessageSupplyException(Exception):
pass
class ShouldNeverHappen(Exception):
def __init__(self, number: int) -> None:
message = (f"SNV{number:05} - please contact @Garmy with the code on"
" the left if you see this")
super().__init__(message)