From d8ee20c402cd10863858402b5c8b3b488273fff0 Mon Sep 17 00:00:00 2001 From: Joscha Date: Fri, 7 Jun 2019 17:30:50 +0000 Subject: [PATCH] Add ShouldNeverHappen exception --- cheuph/__init__.py | 2 ++ cheuph/cursor_rendering.py | 9 ++++----- cheuph/exceptions.py | 8 +++++++- should_never_happens.txt | 3 +++ 4 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 should_never_happens.txt diff --git a/cheuph/__init__.py b/cheuph/__init__.py index 5c12663..c63ff02 100644 --- a/cheuph/__init__.py +++ b/cheuph/__init__.py @@ -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__ diff --git a/cheuph/cursor_rendering.py b/cheuph/cursor_rendering.py index bcf1a25..e059a4c 100644 --- a/cheuph/cursor_rendering.py +++ b/cheuph/cursor_rendering.py @@ -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: diff --git a/cheuph/exceptions.py b/cheuph/exceptions.py index 5c990ae..c113f41 100644 --- a/cheuph/exceptions.py +++ b/cheuph/exceptions.py @@ -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) diff --git a/should_never_happens.txt b/should_never_happens.txt new file mode 100644 index 0000000..4e8a7dd --- /dev/null +++ b/should_never_happens.txt @@ -0,0 +1,3 @@ +SNH0001 - cursor_rendering.py +SNH0002 - cursor_rendering.py +SNH0003 - cursor_rendering.py