Module textual.css.errors
Expand source code
from __future__ import annotations
from rich.console import ConsoleOptions, Console, RenderResult
from rich.traceback import Traceback
from ._help_renderables import HelpText
from .tokenize import Token
from .tokenizer import TokenError
class DeclarationError(Exception):
def __init__(self, name: str, token: Token, message: str | HelpText) -> None:
self.name = name
self.token = token
self.message = message
super().__init__(str(message))
class StyleTypeError(TypeError):
pass
class UnresolvedVariableError(TokenError):
pass
class StyleValueError(ValueError):
"""Raised when the value of a style property is not valid
Attributes:
help_text (HelpText | None): Optional HelpText to be rendered when this
error is raised.
"""
def __init__(self, *args, help_text: HelpText | None = None):
super().__init__(*args)
self.help_text = help_text
def __rich_console__(
self, console: Console, options: ConsoleOptions
) -> RenderResult:
yield Traceback.from_exception(type(self), self, self.__traceback__)
if self.help_text is not None:
yield ""
yield self.help_text
yield ""
class StylesheetError(Exception):
pass
Classes
class DeclarationError (name: str, token: Token, message: str | HelpText)
-
Common base class for all non-exit exceptions.
Expand source code
class DeclarationError(Exception): def __init__(self, name: str, token: Token, message: str | HelpText) -> None: self.name = name self.token = token self.message = message super().__init__(str(message))
Ancestors
- builtins.Exception
- builtins.BaseException
class StyleTypeError (*args, **kwargs)
-
Inappropriate argument type.
Expand source code
class StyleTypeError(TypeError): pass
Ancestors
- builtins.TypeError
- builtins.Exception
- builtins.BaseException
class StyleValueError (*args, help_text: HelpText | None = None)
-
Raised when the value of a style property is not valid
Attributes
help_text (HelpText | None): Optional HelpText to be rendered when this error is raised.
Expand source code
class StyleValueError(ValueError): """Raised when the value of a style property is not valid Attributes: help_text (HelpText | None): Optional HelpText to be rendered when this error is raised. """ def __init__(self, *args, help_text: HelpText | None = None): super().__init__(*args) self.help_text = help_text def __rich_console__( self, console: Console, options: ConsoleOptions ) -> RenderResult: yield Traceback.from_exception(type(self), self, self.__traceback__) if self.help_text is not None: yield "" yield self.help_text yield ""
Ancestors
- builtins.ValueError
- builtins.Exception
- builtins.BaseException
class StylesheetError (*args, **kwargs)
-
Common base class for all non-exit exceptions.
Expand source code
class StylesheetError(Exception): pass
Ancestors
- builtins.Exception
- builtins.BaseException
Subclasses
class UnresolvedVariableError (path: str, code: str, start: tuple[int, int], message: str, end: tuple[int, int] | None = None)
-
Error raised when the CSS cannot be tokenized (syntax error).
Args
path
:str
- Path to source or "
code
:str
- The code being parsed.
start
:tuple[int, int]
- Line number of the error.
message
:str
- A message associated with the error.
end (tuple[int, int] | None): End location of token, or None if not known. Defaults to None.
Expand source code
class UnresolvedVariableError(TokenError): pass
Ancestors
- TokenError
- builtins.Exception
- builtins.BaseException