Errors
MessageFormatError
Bases: 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
DataModelError
Bases: 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
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
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
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
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
FormatError
Bases: MessageFormatError
Base class for all errors raised during formatting.
ResolutionError
Bases: 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
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
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
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
SelectionError
Bases: FormatError
Raised when message selection fails.