Skip to content

bib.bibtexparser.exceptions

Classes

BlockAbortedException

BlockAbortedException(abort_reason, end_index=None)

Bases: ParsingException

Exception where a invalid bibtex file led to an aborted block.

Source code in pybibtexer/bib/bibtexparser/exceptions.py
def __init__(
    self,
    abort_reason: str,
    # Not provided if end of file is reached
    end_index: int | None = None,
):
    self.abort_reason = abort_reason
    self.end_index = end_index

ParserStateException

ParserStateException(message)

Bases: ParsingException

Parser is in a self-inflicted invalid state.

Source code in pybibtexer/bib/bibtexparser/exceptions.py
def __init__(self, message: str):
    self.message = message

ParsingException

Bases: Exception

Generic Exception for parsing errors.

PartialMiddlewareException

PartialMiddlewareException(reasons)

Bases: ParsingException

Exception raised when a middleware could not be fully applied.

Source code in pybibtexer/bib/bibtexparser/exceptions.py
def __init__(self, reasons: list[str]):
    reasons_string = "\n\n=====\n\n".join(reasons)
    super().__init__(f"Middleware could not be fully applied: {reasons_string}")

RegexMismatchException

RegexMismatchException(
    first_match, expected_match, second_match
)

Bases: ParserStateException

Raised when regex matches are inconsistent, implying a bug in the parser.

For example, raised when first match @string{ is not followed by an overlapping match }.

Source code in pybibtexer/bib/bibtexparser/exceptions.py
def __init__(self, first_match, expected_match, second_match):
    self.first_match = first_match
    self.expected_match = expected_match
    self.second_match = second_match
    super().__init__(
        f"Regex mismatch: {first_match} followed by {second_match},"
        f"but expected {expected_match}.\n"
        "This is an python-bibtexparser internal error. "
        "Please report this issue at our issue tracker."
    )