File: exceptions.py

package info (click to toggle)
sphinx-needs 5.1.0%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,108 kB
  • sloc: python: 21,148; javascript: 187; makefile: 95; sh: 29; xml: 10
file content (76 lines) | stat: -rw-r--r-- 1,672 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from __future__ import annotations

from typing import Literal

from sphinx.errors import SphinxError, SphinxWarning


class NeedsApiConfigException(SphinxError):
    """
    A configuration changes collides with the already provided configuration by the user.

    Example: An extension wants to add an already existing needs_type.
    """


class InvalidNeedException(Exception):
    """Raised when a need could not be created/added, due to a validation issue."""

    def __init__(
        self,
        type_: Literal[
            "invalid_kwargs",
            "invalid_type",
            "missing_id",
            "invalid_id",
            "duplicate_id",
            "invalid_status",
            "invalid_tags",
            "invalid_constraints",
            "invalid_jinja_content",
            "invalid_template",
            "global_option",
        ],
        message: str,
    ) -> None:
        self._type = type_
        self._message = message
        super().__init__(f"{message} [{type_}]")

    @property
    def type(
        self,
    ) -> Literal[
        "invalid_kwargs",
        "invalid_type",
        "missing_id",
        "invalid_id",
        "duplicate_id",
        "invalid_status",
        "invalid_tags",
        "invalid_constraints",
        "invalid_jinja_content",
        "invalid_template",
        "global_option",
    ]:
        return self._type

    @property
    def message(self) -> str:
        return self._message


class NeedsApiConfigWarning(SphinxWarning):
    pass


class NeedsInvalidException(SphinxError):
    pass


class NeedsConstraintFailed(SphinxError):
    pass


class NeedsInvalidFilter(SphinxError):
    pass