from pathlib import Path
from tempfile import TemporaryDirectory
from babregen import SpecError, load_spec, make_sample_repo
with TemporaryDirectory() as tmp:
root = make_sample_repo(Path(tmp) / "demo")
unit = root / "regen" / "units" / "core.calc.toml"
unit.write_text(unit.read_text().replace('"fast"', '"warp"'))
try:
load_spec(root)
except SpecError as exc:
print(str(exc).replace(tmp, "<tmp>"))
print(exc.path.name, exc.line)spec.SpecError
spec.SpecError(detail, *, path=None, line=None, suggestion=None, located=True)A file under regen/ is missing a field or holds a value outside its vocabulary.
The message is the text the command line prints. path and line are the location of the error: the file, and the line when the error has one.
Attributes
| Name | Type | Description |
|---|---|---|
| detail | The message without its location: what is wrong, without the file, the line and the suggestion. str of the error is the location, the detail and the suggestion put together. |
|
| path | The file the error is about, or None. | |
| line | The 1-based line of the error, or None. An unknown key carries the line of the key, a TOML syntax error its line (from the error, or from its text on Python versions whose error has no lineno). |
|
| suggestion | A similar valid name (an unknown key, an unknown unit), or None. When there is one the message ends with ; a similar name exists: 'X'. |