Skip to content

Errors

MessageFormatError

Bases: Exception

Base class for all messageformat2 errors.

Use this class to catch arbitrary messageformat2 errors.

Source code in messageformat2/errors.py
1
2
3
4
5
class MessageFormatError(Exception):
    """Base class for all messageformat2 errors.

    Use this class to catch arbitrary messageformat2 errors.
    """

ParseError

Bases: MessageFormatError

Raised when invalid syntax is encountered during parsing.

Examples:

>>> from messageformat2 import Message
>>> Message("{ Unclosed pattern")
Traceback (most recent call last):
...
messageformat2.errors.ParseError: ...
Source code in messageformat2/errors.py
class ParseError(MessageFormatError):
    """Raised when invalid syntax is encountered during parsing.

    Examples:
        >>> from messageformat2 import Message
        >>> Message("{ Unclosed pattern") # doctest: +ELLIPSIS
        Traceback (most recent call last):
        ...
        messageformat2.errors.ParseError: ...
    """

DataModelError

Bases: MessageFormatError

Base class for all messageformat2 data model errors.

Source code in messageformat2/errors.py
class DataModelError(MessageFormatError):
    """Base class for all messageformat2 data model errors."""

VariantKeyMismatch

Bases: DataModelError

Raised when the number of variant keys does not match the number of selectors.

Examples:

>>> from messageformat2 import Message
>>> Message(".match {$count :integer} 0 1 {{You have no notifications.}}")
Traceback (most recent call last):
...
messageformat2.errors.VariantKeyMismatch: ...
Source code in messageformat2/errors.py
class VariantKeyMismatch(DataModelError):
    """Raised when the number of variant keys does not match the number of selectors.

    Examples:
        >>> from messageformat2 import Message
        >>> Message(".match {$count :integer} 0 1 {{You have no notifications.}}") # doctest: +ELLIPSIS
        Traceback (most recent call last):
        ...
        messageformat2.errors.VariantKeyMismatch: ...
    """

MissingFallbackVariant

Bases: DataModelError

Raised when a fallback variant (all catch-all keys) is not provided.

Examples:

>>> from messageformat2 import Message
>>> Message(".match {$count :integer} one {{You have one notification.}}")
Traceback (most recent call last):
...
messageformat2.errors.MissingFallbackVariant: Missing fallback variant
Source code in messageformat2/errors.py
class MissingFallbackVariant(DataModelError):
    """Raised when a fallback variant (all catch-all keys) is not provided.

    Examples:
        >>> from messageformat2 import Message
        >>> Message(".match {$count :integer} one {{You have one notification.}}") # doctest: +ELLIPSIS
        Traceback (most recent call last):
        ...
        messageformat2.errors.MissingFallbackVariant: Missing fallback variant
    """

MissingSelectorAnnotation

Bases: DataModelError

Raised when a selector annotation is missing.

Examples:

>>> from messageformat2 import Message
>>> Message(".match {$count} * {{You have {$count} notifications.}}")
Traceback (most recent call last):
...
messageformat2.errors.MissingSelectorAnnotation: ...
Source code in messageformat2/errors.py
class MissingSelectorAnnotation(DataModelError):
    """Raised when a selector annotation is missing.

    Examples:
        >>> from messageformat2 import Message
        >>> Message(".match {$count} * {{You have {$count} notifications.}}") # doctest: +ELLIPSIS
        Traceback (most recent call last):
        ...
        messageformat2.errors.MissingSelectorAnnotation: ...
    """

DuplicateDeclaration

Bases: DataModelError

Raised when a variable is declared more than once.

This includes variables declared as '.input'.

Examples:

>>> from messageformat2 import Message
>>> Message(".input {$count} .local $count = {42} {{Duplicate declaration}}")
Traceback (most recent call last):
...
messageformat2.errors.DuplicateDeclaration: ...
Source code in messageformat2/errors.py
class DuplicateDeclaration(DataModelError):
    """Raised when a variable is declared more than once.

    This includes variables declared as '.input'.

    Examples:
        >>> from messageformat2 import Message
        >>> Message(".input {$count} .local $count = {42} {{Duplicate declaration}}") # doctest: +ELLIPSIS
        Traceback (most recent call last):
        ...
        messageformat2.errors.DuplicateDeclaration: ...
    """

DuplicateOptionName

Bases: DataModelError

Raised when an option is declared more than once.

Examples:

>>> from messageformat2 import Message
>>> Message("{42 :integer opt=1 opt=2}")
Traceback (most recent call last):
...
messageformat2.errors.DuplicateOptionName: ...
Source code in messageformat2/errors.py
class DuplicateOptionName(DataModelError):
    """Raised when an option is declared more than once.

    Examples:
        >>> from messageformat2 import Message
        >>> Message("{42 :integer opt=1 opt=2}") # doctest: +ELLIPSIS
        Traceback (most recent call last):
        ...
        messageformat2.errors.DuplicateOptionName: ...
    """

FormatError

Bases: MessageFormatError

Base class for all errors raised during formatting.

Source code in messageformat2/errors.py
class FormatError(MessageFormatError):
    """Base class for all errors raised during formatting."""

ResolutionError

Bases: FormatError

Raised when a part of the message cannot be determined.

Source code in messageformat2/errors.py
class ResolutionError(FormatError):
    """Raised when a part of the message cannot be determined."""

UnresolvedVariable

Bases: ResolutionError

Raised when a variable cannot be resolved.

Examples:

>>> from messageformat2 import Message
>>> Message("Hello, {$name}!").format()
Traceback (most recent call last):
...
messageformat2.errors.UnresolvedVariable: ...
Source code in messageformat2/errors.py
class UnresolvedVariable(ResolutionError):
    """Raised when a variable cannot be resolved.

    Examples:
        >>> from messageformat2 import Message
        >>> Message("Hello, {$name}!").format() # doctest: +ELLIPSIS
        Traceback (most recent call last):
        ...
        messageformat2.errors.UnresolvedVariable: ...
    """

UnknownFunction

Bases: ResolutionError

Raised when a function is not found.

Examples:

>>> from messageformat2 import Message
>>> Message("{Alice :unknown}").format()
Traceback (most recent call last):
...
messageformat2.errors.UnknownFunction: ...
Source code in messageformat2/errors.py
class UnknownFunction(ResolutionError):
    """Raised when a function is not found.

    Examples:
        >>> from messageformat2 import Message
        >>> Message("{Alice :unknown}").format() # doctest: +ELLIPSIS
        Traceback (most recent call last):
        ...
        messageformat2.errors.UnknownFunction: ...
    """

UnsupportedExpression

Bases: ResolutionError

Raised when an expression uses reserved syntax.

Examples:

>>> from messageformat2 import Message
>>> Message("The value is {!horse}").format()
Traceback (most recent call last):
...
messageformat2.errors.UnsupportedExpression: ...
Source code in messageformat2/errors.py
class UnsupportedExpression(ResolutionError):
    """Raised when an expression uses reserved syntax.

    Examples:
        >>> from messageformat2 import Message
        >>> Message("The value is {!horse}").format() # doctest: +ELLIPSIS
        Traceback (most recent call last):
        ...
        messageformat2.errors.UnsupportedExpression: ...
    """

UnsupportedStatement

Bases: ResolutionError

Raised when the message contains a reserved statement.

Examples:

>>> from messageformat2 import Message
>>> Message(".unknown {$x} .match {$x :string} * {{}}").format()
Traceback (most recent call last):
...
messageformat2.errors.UnsupportedStatement: ...
Source code in messageformat2/errors.py
class UnsupportedStatement(ResolutionError):
    """Raised when the message contains a reserved statement.

    Examples:
        >>> from messageformat2 import Message
        >>> Message(".unknown {$x} .match {$x :string} * {{}}").format() # doctest: +ELLIPSIS
        Traceback (most recent call last):
        ...
        messageformat2.errors.UnsupportedStatement: ...
    """

SelectionError

Bases: FormatError

Raised when message selection fails.

Source code in messageformat2/errors.py
class SelectionError(FormatError):
    """Raised when message selection fails."""