Skip to content

Commit

Permalink
0.1.3: improved TOMLBaseSingleError docstring and add .msg attribute
Browse files Browse the repository at this point in the history
maps closer to pydantic errors; should make more sense for devs coming from pydantic
  • Loading branch information
markjoshwel committed Mar 4, 2024
1 parent 29f7cf5 commit d492563
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# tomlantic

> [!WARNING]
> tomlantic is at 0.1.2 and currently, only i use it myself. it isn't battle tested,
> tomlantic is at 0.1.3 and currently, only i use it myself. it isn't battle tested,
> so issues may arise.
> if you're willing to run into potential bugs and issues, feel free to use it!
Expand Down Expand Up @@ -191,7 +191,10 @@ base exception class for all tomlantic errors
- attributes:
- loc: `tuple[str, ...]`
the location of the error in the toml document
example: `('settings', 'name')`
example: `('settings', 'name') = settings.name`

- msg: `str`
the error 'message' (if any)

- pydantic_error: [`pydantic_core.ErrorDetails`](https://docs.pydantic.dev/latest/api/pydantic_core/#pydantic_core.ErrorDetails)
the original pydantic error, this is what you see in the list of errors when you
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[tool.poetry]
name = "tomlantic"
version = "0.1.2"
version = "0.1.3"
description = "marrying pydantic models and tomlkit documents"
authors = ["Mark Joshwel <mark@joshwel.co>"]
license = "Unlicense"
readme = "README.md"
include = ["README.md"]

[tool.poetry.dependencies]
python = "^3.8"
Expand Down
11 changes: 10 additions & 1 deletion tomlantic/tomlantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,17 @@ class TomlanticException(Exception):


class TOMLBaseSingleError(TomlanticException):
"""base exception class for single errors, e.g. TOMLMissingError, TOMLValueError"""
"""
base exception class for single errors, e.g. TOMLMissingError, TOMLValueError
attributes:
- loc: `tuple[str]`
- msg: `str`
- pydantic_error: `pydantic_core.ErrorDetails`
"""

loc: Tuple[str, ...]
msg: str = ""
pydantic_error: ErrorDetails

def __init__(
Expand All @@ -158,6 +166,7 @@ def __init__(
self.loc = loc
self.pydantic_error = pydantic_error
super().__init__(*args)
self.msg = str(self)


class TOMLMissingError(TOMLBaseSingleError):
Expand Down

0 comments on commit d492563

Please sign in to comment.