Skip to content

Commit

Permalink
feat: add module for custom exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
pivoshenko committed Sep 1, 2024
1 parent 6fa7bd9 commit d21b1df
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/poetry_plugin_dotenv/dotenv/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from typing import NamedTuple
from typing import TYPE_CHECKING

from poetry_plugin_dotenv.exceptions import PoetryPluginDotenvPatternError


if TYPE_CHECKING: # pragma: no cover
from collections.abc import Iterator
Expand All @@ -31,10 +33,6 @@ class Binding(NamedTuple):
error: bool


class DotenvParseError(Exception):
"""Exception for dotenv parse errors."""


def make_regex(string: str, extra_flags: int = 0) -> re.Pattern[str]:
"""Construct a regex expression."""

Expand Down Expand Up @@ -128,7 +126,7 @@ def read_regex(self, regex: re.Pattern[str]) -> tuple[str, ...]:

if match is None:
msg = "Pattern not found."
raise DotenvParseError(msg)
raise PoetryPluginDotenvPatternError(msg)

# fmt: off
matched = self.string[match.start(): match.end()]
Expand Down Expand Up @@ -230,7 +228,7 @@ def parse_binding(reader: Reader) -> Binding:
error=False,
)

except DotenvParseError:
except PoetryPluginDotenvPatternError:
reader.read_regex(_rest_of_line)
return Binding(
key=None,
Expand Down
11 changes: 11 additions & 0 deletions src/poetry_plugin_dotenv/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""Module defines custom exceptions that are used across plugin."""

from __future__ import annotations


class PoetryPluginDotenvError(Exception):
"""Base exception."""


class PoetryPluginDotenvPatternError(PoetryPluginDotenvError):
"""Exception raised when a dotenv pattern is not valid or not found."""

0 comments on commit d21b1df

Please sign in to comment.