Add ShouldNeverHappen exception
This commit is contained in:
parent
a9ddf27525
commit
d8ee20c402
4 changed files with 16 additions and 6 deletions
|
|
@ -7,6 +7,7 @@ from .cursor_rendering import *
|
||||||
from .cursor_tree_widget import *
|
from .cursor_tree_widget import *
|
||||||
from .element import *
|
from .element import *
|
||||||
from .element_supply import *
|
from .element_supply import *
|
||||||
|
from .exceptions import *
|
||||||
from .markup import *
|
from .markup import *
|
||||||
from .rendered_element_cache import *
|
from .rendered_element_cache import *
|
||||||
|
|
||||||
|
|
@ -19,5 +20,6 @@ __all__ += cursor_rendering.__all__
|
||||||
__all__ += cursor_tree_widget.__all__
|
__all__ += cursor_tree_widget.__all__
|
||||||
__all__ += element.__all__
|
__all__ += element.__all__
|
||||||
__all__ += element_supply.__all__
|
__all__ += element_supply.__all__
|
||||||
|
__all__ += exceptions.__all__
|
||||||
__all__ += markup.__all__
|
__all__ += markup.__all__
|
||||||
__all__ += rendered_element_cache.__all__
|
__all__ += rendered_element_cache.__all__
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ from typing import Generic, List, Optional, Tuple, TypeVar
|
||||||
from .attributed_lines import AttributedLines
|
from .attributed_lines import AttributedLines
|
||||||
from .element import Element, Id, Message, RenderedElement, RenderedMessage
|
from .element import Element, Id, Message, RenderedElement, RenderedMessage
|
||||||
from .element_supply import ElementSupply
|
from .element_supply import ElementSupply
|
||||||
|
from .exceptions import ShouldNeverHappen
|
||||||
from .markup import AT, AttributedText, Attributes
|
from .markup import AT, AttributedText, Attributes
|
||||||
from .rendered_element_cache import RenderedElementCache
|
from .rendered_element_cache import RenderedElementCache
|
||||||
|
|
||||||
|
|
@ -408,11 +409,9 @@ class CursorTreeRenderer(Generic[E]):
|
||||||
return 0, middle_index
|
return 0, middle_index
|
||||||
|
|
||||||
if middle_index < self.lines.upper_offset:
|
if middle_index < self.lines.upper_offset:
|
||||||
raise Exception()
|
|
||||||
attrs, _ = lines[0]
|
attrs, _ = lines[0]
|
||||||
index = self.lines.upper_offset
|
index = self.lines.upper_offset
|
||||||
elif middle_index > self.lines.lower_offset:
|
elif middle_index > self.lines.lower_offset:
|
||||||
raise Exception()
|
|
||||||
attrs, _ = lines[-1]
|
attrs, _ = lines[-1]
|
||||||
index = self.lines.lower_offset
|
index = self.lines.lower_offset
|
||||||
else:
|
else:
|
||||||
|
|
@ -535,7 +534,7 @@ class CursorTreeRenderer(Generic[E]):
|
||||||
message = self._cache.get(mid)
|
message = self._cache.get(mid)
|
||||||
|
|
||||||
if message is None:
|
if message is None:
|
||||||
raise Exception() # TODO use better exception
|
raise ShouldNeverHappen(1)
|
||||||
|
|
||||||
height += len(message.lines)
|
height += len(message.lines)
|
||||||
|
|
||||||
|
|
@ -553,7 +552,7 @@ class CursorTreeRenderer(Generic[E]):
|
||||||
below_new = self._element_id_below_cursor(new_cursor_id)
|
below_new = self._element_id_below_cursor(new_cursor_id)
|
||||||
|
|
||||||
if above_old is None:
|
if above_old is None:
|
||||||
raise Exception() # TODO use better exception
|
raise ShouldNeverHappen(2)
|
||||||
|
|
||||||
# Moving horizontally at the bottom of the supply
|
# Moving horizontally at the bottom of the supply
|
||||||
if below_new is None:
|
if below_new is None:
|
||||||
|
|
@ -579,7 +578,7 @@ class CursorTreeRenderer(Generic[E]):
|
||||||
above_new = self._element_id_above_cursor(new_cursor_id)
|
above_new = self._element_id_above_cursor(new_cursor_id)
|
||||||
|
|
||||||
if above_new is None:
|
if above_new is None:
|
||||||
raise Exception() # TODO use better exception
|
raise ShouldNeverHappen(3)
|
||||||
|
|
||||||
# Moving horizontally at the bottom of the supply
|
# Moving horizontally at the bottom of the supply
|
||||||
if below_old is None:
|
if below_old is None:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,10 @@
|
||||||
__all__ = ["MessageSupplyException"]
|
__all__ = ["MessageSupplyException", "ShouldNeverHappen"]
|
||||||
|
|
||||||
class MessageSupplyException(Exception):
|
class MessageSupplyException(Exception):
|
||||||
pass
|
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)
|
||||||
|
|
|
||||||
3
should_never_happens.txt
Normal file
3
should_never_happens.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
SNH0001 - cursor_rendering.py
|
||||||
|
SNH0002 - cursor_rendering.py
|
||||||
|
SNH0003 - cursor_rendering.py
|
||||||
Loading…
Add table
Add a link
Reference in a new issue