errors

This module contains the exceptions raised by the package.

Data

UNDEFINED = UNDEFINED

A sentinel value to specify that something is undefined. When evaluated, the value is falsy.

New in version 2.0.0.

Exceptions

exception AttributeResolutionError(attribute_name, object_, thing=UNDEFINED, suggestion=None)[source]

Bases: EvaluationError

An error raised with an attribute can not be resolved to a value.

New in version 2.0.0.

__init__(attribute_name, object_, thing=UNDEFINED, suggestion=None)[source]
Parameters:
  • attribute_name (str) – The name of the symbol that can not be resolved.

  • object – The value that attribute_name was used as an attribute for.

  • thing – The root-object that was used to resolve object.

  • suggestion (str) – An optional suggestion for a valid attribute name.

Changed in version 3.2.0: Added the suggestion parameter.

attribute_name

The name of the symbol that can not be resolved.

object

The value that attribute_name was used as an attribute for.

suggestion

An optional suggestion for a valid attribute name.

thing

The root-object that was used to resolve object.

exception AttributeTypeError(attribute_name, object_type, is_value, is_type, expected_type)[source]

Bases: EvaluationError

An error raised when an attribute with type information is resolved to a Python value that is not of that type.

__init__(attribute_name, object_type, is_value, is_type, expected_type)[source]
Parameters:
  • attribute_name (str) – The name of the symbol that can not be resolved.

  • object_type – The value that attribute_name was used as an attribute for.

  • is_value – The native Python value of the incompatible attribute.

  • is_type – The rule-engine type of the incompatible attribute.

  • expected_type – The rule-engine type that was expected for this attribute.

attribute_name

The name of the attribute that is of an incompatible type.

expected_type

The rule-engine type that was expected for this attribute.

is_type

The rule-engine type of the incompatible attribute.

is_value

The native Python value of the incompatible attribute.

object_type

The object on which the attribute was resolved.

exception DatetimeSyntaxError(message, value)[source]

Bases: SyntaxError

An error raised for issues regarding the use of improperly formatted datetime expressions.

__init__(message, value)[source]
Parameters:
  • message (str) – A text description of what error occurred.

  • value (str) – The datetime value which contains the syntax error which caused this exception to be raised.

value

The datetime value which contains the syntax error which caused this exception to be raised.

exception FloatSyntaxError(message, value)[source]

Bases: SyntaxError

An error raised for issues regarding the use of improperly formatted float expressions.

New in version 4.0.0.

__init__(message, value)[source]
Parameters:
  • message (str) – A text description of what error occurred.

  • value (str) – The float value which contains the syntax error which caused this exception to be raised.

value

The float value which contains the syntax error which caused this exception to be raised.

exception EngineError(message='')[source]

Bases: Exception

The base exception class from which other exceptions within this package inherit.

__init__(message='')[source]
Parameters:

message (str) – A text description of what error occurred.

message

A text description of what error occurred.

exception EvaluationError(message='')[source]

Bases: EngineError

An error raised for issues which occur while the rule is being evaluated. This can occur at parse time while AST nodes are being evaluated during the reduction phase.

exception FunctionCallError(message, error=None, function_name=None)[source]

Bases: EvaluationError

An error raised when there is an issue calling a function.

New in version 4.0.0.

__init__(message, error=None, function_name=None)[source]
Parameters:

message (str) – A text description of what error occurred.

error

The exception from which this error was triggered.

exception LookupError(container, item)[source]

Bases: EvaluationError

An error raised when a lookup operation fails to obtain and item from a container. This is analogous to a combination of Python’s builtin IndexError and KeyError exceptions.

New in version 2.4.0.

__init__(container, item)[source]
Parameters:
  • container – The container object that the lookup was performed on.

  • item – The item that was used as either the key or index of container for the lookup.

container

The container object that the lookup was performed on.

item

The item that was used as either the key or index of container for the lookup.

exception RegexSyntaxError(message, error, value)[source]

Bases: SyntaxError

An error raised for issues regarding the use of improper regular expression syntax.

__init__(message, error, value)[source]
Parameters:
  • message (str) – A text description of what error occurred.

  • error (re.error) – The re.error exception from which this error was triggered.

  • value (str) – The regular expression value which contains the syntax error which caused this exception to be raised.

error

The re.error exception from which this error was triggered.

value

The regular expression value which contains the syntax error which caused this exception to be raised.

exception RuleSyntaxError(message, token=None)[source]

Bases: SyntaxError

An error raised for issues identified while parsing the grammar of the rule text.

__init__(message, token=None)[source]
Parameters:
  • message (str) – A text description of what error occurred.

  • token – The PLY token (if available) which is related to the syntax error.

token

The PLY token (if available) which is related to the syntax error.

exception SymbolResolutionError(symbol_name, symbol_scope=None, thing=UNDEFINED, suggestion=None)[source]

Bases: EvaluationError

An error raised when a symbol name is not able to be resolved to a value.

__init__(symbol_name, symbol_scope=None, thing=UNDEFINED, suggestion=None)[source]
Parameters:
  • symbol_name (str) – The name of the symbol that can not be resolved.

  • symbol_scope (str) – The scope of where the symbol should be valid for resolution.

  • thing – The root-object that was used to resolve the symbol.

  • suggestion (str) – An optional suggestion for a valid symbol name.

Changed in version 2.0.0: Added the thing parameter.

Changed in version 3.2.0: Added the suggestion parameter.

suggestion

An optional suggestion for a valid symbol name.

symbol_name

The name of the symbol that can not be resolved.

symbol_scope

The scope of where the symbol should be valid for resolution.

thing

The root-object that was used to resolve the symbol.

exception SymbolTypeError(symbol_name, is_value, is_type, expected_type)[source]

Bases: EvaluationError

An error raised when a symbol with type information is resolved to a Python value that is not of that type.

__init__(symbol_name, is_value, is_type, expected_type)[source]
Parameters:
  • symbol_name (str) – The name of the symbol that is of an incompatible type.

  • is_value – The native Python value of the incompatible symbol.

  • is_type – The rule-engine type of the incompatible symbol.

  • expected_type – The rule-engine type that was expected for this symbol.

expected_type

The rule-engine type that was expected for this symbol.

is_type

The rule-engine type of the incompatible symbol.

is_value

The native Python value of the incompatible symbol.

symbol_name

The name of the symbol that is of an incompatible type.

exception SyntaxError(message='')[source]

Bases: EngineError

A base error for syntax related issues.

exception TimedeltaSyntaxError(message, value)[source]

Bases: SyntaxError

An error raised for issues regarding the use of improperly formatted timedelta expressions.

New in version 3.5.0.

__init__(message, value)[source]
Parameters:
  • message (str) – A text description of what error occurred.

  • value (str) – The timedelta value which contains the syntax error which caused this exception to be raised.

value

The timedelta value which contains the syntax error which caused this exception to be raised.

Exception Hierarchy

The class hierarchy for Rule Engine exceptions is:

EngineError
 +-- EvaluationError
      +-- AttributeResolutionError
      +-- AttributeTypeError
      +-- FunctionCallError
      +-- LookupError
      +-- SymbolResolutionError
      +-- SymbolTypeError
 +-- SyntaxError
      +-- DatetimeSyntaxError
      +-- FloatSyntaxError
      +-- RegexSyntaxError
      +-- RuleSyntaxError
      +-- TimedeltaSyntaxError