Skip to content

Errors

tibiawikisql.errors

Custom exceptions used by the package.

Classes:

Name Description
TibiaWikiSqlError

Base class for all exceptions raised by tibiawiki-sql.

AttributeParsingError

Error raised when trying to parse an attribute.

ArticleParsingError

Error raised when an article failed to be parsed.

TemplateNotFoundError

Error raised when the required template is not found in the article.

DatabaseError

Error raised when a database related error happens.

InvalidColumnValueError

Error raised when an invalid value is assigned to a column.

SchemaError

Error raised for invalid schema definitions.

TibiaWikiSqlError

Bases: Exception

Base class for all exceptions raised by tibiawiki-sql.

AttributeParsingError

AttributeParsingError(cause: type[Exception])

Bases: TibiaWikiSqlError

Error raised when trying to parse an attribute.

Parameters:

Name Type Description Default
cause type[Exception]

The exception that caused this.

required
Source code in tibiawikisql/errors.py
def __init__(self, cause: type[Exception]) -> None:
    """Create an instance of the class.

    Args:
        cause: The exception that caused this.

    """
    super().__init__(f"{cause.__class__.__name__}: {cause}")

ArticleParsingError

ArticleParsingError(
    article: Article,
    msg: str | None = None,
    cause: type[Exception] | None = None,
)

Bases: TibiaWikiSqlError

Error raised when an article failed to be parsed.

Parameters:

Name Type Description Default
article Article

The article that failed to parse.

required
msg str | None

An error message for the error.

None
cause type[Exception] | None

The original exception that caused the parsing to fail.

None
Source code in tibiawikisql/errors.py
def __init__(self, article: Article, msg: str | None = None, cause: type[Exception] | None = None) -> None:
    """Create an instance of the class.

    Args:
        article: The article that failed to parse.
        msg: An error message for the error.
        cause: The original exception that caused the parsing to fail.
    """
    self.article = article
    if cause:
       msg = f"Error parsing article: `{article.title}` | {cause.__class__.__name__}: {cause}"
    else:
        msg = f"Error parsing article: `{article.title}` | {msg}"
    super().__init__(msg)

TemplateNotFoundError

TemplateNotFoundError(
    article: Article, parser: type[BaseParser]
)

Bases: ArticleParsingError

Error raised when the required template is not found in the article.

Parameters:

Name Type Description Default
article Article

The article that failed to parse.

required
parser type[BaseParser]

The parser class used.

required
Source code in tibiawikisql/errors.py
def __init__(self, article: Article, parser: type[BaseParser]) -> None:
    """Create an instance of the class.

    Args:
        article: The article that failed to parse.
        parser: The parser class used.
    """
    super().__init__(article, f"Template `{parser.template_name}` not found.")

DatabaseError

Bases: TibiaWikiSqlError

Error raised when a database related error happens.

InvalidColumnValueError

InvalidColumnValueError(
    table: type[Table], column: Column, message: str
)

Bases: TibiaWikiSqlError

Error raised when an invalid value is assigned to a column.

Parameters:

Name Type Description Default
table type[Table]

The table where the column is located.

required
column Column

The column with the error.

required
message str

A brief description of the error.

required
Source code in tibiawikisql/errors.py
def __init__(self, table: type[Table], column: Column, message: str) -> None:
    """Create an instance of the class.

    Args:
        table: The table where the column is located.
        column: The column with the error.
        message: A brief description of the error.
    """
    super().__init__(f"Column {column.name!r} in table {table.__tablename__!r}: {message}")
    self.table = table
    self.column = column

SchemaError

Bases: DatabaseError

Error raised for invalid schema definitions.

Notes

This error is raised very early when running, to verify that classes are defined correctly, so it is not an error that should be seen when using the library.