error_callbacks

Creating Error functions:

Error functions are used by cooked_input to report errors from convertors and validators. Error functions take three parameters:

  • fmt_str: a Python format string for the error. The format string can use the arguments {value} and {error_content}.
  • value: the value that caused the error from the convertor or validator.
  • error_content: the particulars of the error message from the convertor or validator.

The following example prints errors to sys.stdout:

def print_error(fmt_str, value, error_content):
    print(fmt_str.format(value=value, error_content=error_content))

An example of a convertor format string is as follows:

generic_convertor_fmt = '{value} cannot be converted to {error_content}'

and similarly for validation:

generic_validator_fmt = '{value} {error_content}'

error_callbacks:

log_error

cooked_input.log_error(fmt_str, value, error_content)

send errors to the log. See logging for details on using logs.

Parameters:
  • fmt_str (str) –

    a Python format string for the error. Can use arguments {value} and {error_content} in the format string

  • value (Any) – the value the caused the error.
  • error_content (str) – additional information for the error
Returns:

None

silent_error

cooked_input.silent_error(fmt_str, value, error_content)

Ignores errors, causing them to be silent.

Parameters:
  • fmt_str (str) –

    a Python format string for the error. Can use arguments {value} and {error_content} in the format string

  • value (Any) – the value the caused the error
  • error_content (str) – additional information for the error
Returns:

None