Documentation Index
Fetch the complete documentation index at: https://mintlify.com/iFamishedX/HungerLib/llms.txt
Use this file to discover all available pages before exploring further.
Validator is a base class for building configuration schema validators in HungerLib. Subclass it, override validate_schema() to add per-field checks using check_field() and validate_key_types(), then call run(*configs) to execute all validations and raise the highest-priority exception if any issues are found. The exception hierarchy (FatalError → TypeMismatchError → FallbackError → RecommendedError) lets callers catch exactly the severity they care about.
Constructor
str.format(**kwargs) where the keys correspond to the placeholders shown below.
Template used when a field is absent from the config and its rule is
"required". Placeholder: {field} — the field name.Template used when a field is absent and its rule is
"recommended". Placeholders: {field}, {fallback} — the fallback value that will be used.Template used when a
"required" field still holds its fallback/default value. Placeholders: {field}, {value}.Template used when a
"recommended" field is using its fallback value. Placeholders: {field}, {value}.Template used when
validate_key_types() detects a type mismatch. Placeholders: {schema}, {field}, {expected}, {actual}, {value}.run() is called:
validator.errors— list of error message stringsvalidator.warnings— list of warning stringsvalidator.fallbacks— list of fallback-usage stringsvalidator.recommended— list of recommended-field strings
Methods
check_field()
self.errors, self.fallbacks, or self.recommended based on whether the field is missing, using a fallback, or within tolerance.
The method reads three attributes from obj:
obj.raw— the raw parsed config object (e.g. loaded from YAML). Missing keys appear asNone.obj.fallbacks— a companion object holding fallback/default values for each field.obj.<name>— the resolved value after fallback substitution.
"required", "recommended", or "optional") is read from obj.__class__.rules.<name> if the rules attribute exists; otherwise it defaults to "optional".
The config object to inspect. Must have
raw, fallbacks, and the named attribute.The attribute name to check.
None. Results are accumulated in self.errors, self.fallbacks, and self.recommended.
validate_key_types()
dataclass schema and compares the type of each field value on obj against the declared type annotation. Any mismatches are appended to self.errors.
The config object whose attribute values will be type-checked.
A
dataclass class (not an instance). Its fields() are iterated to get field names and expected types. Fields whose names start with "__" are skipped. Fields with a None value on obj are also skipped (assumed not yet set).None. Type mismatch messages are appended to self.errors.
validate_schema()
run(). The base implementation is a no-op. Subclasses override this method to call check_field(), validate_key_types(), and any custom validation logic.
The config object passed through from
run(*configs).None.
run()
validate_schema(cfg) for each one, then raises the highest-priority exception if any issues were collected, or returns the clean report string if everything passes.
Exception priority (highest first):
| Condition | Exception raised |
|---|---|
self.errors is non-empty | FatalError |
Any error contains "expected" (type mismatch) | TypeMismatchError |
self.fallbacks is non-empty | FallbackError |
self.recommended is non-empty | RecommendedError |
One or more config objects to validate. Each is passed to
validate_schema().str — the result of format_report(). Returns "all configs valid" if no issues were found.
Raises FatalError, TypeMismatchError, FallbackError, or RecommendedError depending on the collected issues.
format_report()
str — a formatted report. Returns "all configs valid" if all four lists are empty.
Example output:
Exception Classes
All exceptions carry the same five attributes and can be caught individually or as their common baseValidationError.
ValidationError
Exception.
The full formatted report string from
format_report(). Also the exception message (str(e)).List of fatal/type-error message strings. Empty list if none.
List of warning message strings. Empty list if none.
List of fallback-usage message strings. Empty list if none.
List of missing-recommended-field message strings. Empty list if none.
FatalError
run() when self.errors is non-empty, indicating that one or more required fields are missing or invalid. This is the highest-severity exception. Catch it to detect hard configuration failures that prevent the application from running.
Inherits all attributes from ValidationError.
TypeMismatchError
run() when errors contain type mismatch messages (those containing "expected"). Indicates that a field is present but has the wrong Python type. Inherits all attributes from ValidationError.
FallbackError
run() when self.fallbacks is non-empty, meaning one or more "recommended" fields are using their fallback values. Useful for issuing startup warnings without blocking execution. Inherits all attributes from ValidationError.
RecommendedError
run() when self.recommended is non-empty, indicating that recommended fields were absent from the config. The lowest-severity validation exception. Inherits all attributes from ValidationError.
Catching Exceptions
Because all four exception classes share the sameValidationError base, you can catch them at whatever granularity your application requires: