| Author: | Ken Kundert |
|---|---|
| Version: | 0.2 |
| Released: | 2026-06-28 |
A convenience function used for reporting voluptuous errors from nestedtext with inform. Here is a typical use of this function:
>>> from voluptuous import Schema, Invalid, MultipleInvalid, Required
>>> from voluptuous_errors import report_voluptuous_errors
>>> from inform import error, os_error, terminate
>>> import nestedtext as nt
>>> try:
... settings_path = Path('settings.nt')
... settings = nt.load(
... settings_path,
... keymap = (keymap:={}),
... )
... settings = schema(settings)
>>> except nt.NestedTextError as e:
... e.report()
>>> except MultipleInvalid as e:
... report_voluptuous_errors(e, keymap, settings_path)
>>> except OSError as e:
... error(os_error(e))
>>> terminate()
This code reports all errors found by Voluptuous when reading the settings file. It employs the NestedText keymap facility to annotate the error messages with helpful context such as line numbers.
You can map Voluptuous error messages by importing and modifying voluptuous_error_msg_mappings. For example:
voluptuous_error_msg_mappings["expected a table name"] = ("unknown table.", "key")
The value consists of two values, the new message, and the location they message refers to. This second value may be either "key" or "value".
- Return error count
- Improve error message (include value as codicil if appropriate).
- Initial version.