StrictDoc Documentation
strictdoc/backend/sdoc/errors/document_tree_error.py
Source file coverage
Path:
strictdoc/backend/sdoc/errors/document_tree_error.py
Lines:
35
Non-empty lines:
29
Non-empty lines covered with requirements:
29 / 29 (100.0%)
Functions:
5
Functions covered by requirements:
5 / 5 (100.0%)
1
"""
2
@relation(SDOC-SRS-30, scope=file)
3
"""
4
 
5
from typing import List
6
 
7
 
8
class DocumentTreeError(Exception):
9
    def __init__(self, problem_uid: str, cycled_uids: List[str]) -> None:
10
        super().__init__()
11
        self.problem_uid: str = problem_uid
12
        self.cycled_uids: List[str] = cycled_uids
13
 
14
    @staticmethod
15
    def cycle_error(
16
        problem_uid: str, cycled_uids: List[str]
17
    ) -> "DocumentTreeError":
18
        return DocumentTreeError(problem_uid, cycled_uids)
19
 
20
    def to_print_message(self) -> str:
21
        cycled_uids = ", ".join(self.cycled_uids)
22
        message = (
23
            "error: document tree: "
24
            "a cycle detected: requirements in the document tree must not "
25
            "reference each other.\n"
26
            f"Problematic UID: {self.problem_uid}.\nCycle: {cycled_uids}.\n"
27
        )
28
        return message
29
 
30
    def to_validation_message(self) -> str:
31
        return (
32
            "A cycle detected: requirements in the document tree must not "
33
            "reference each other. "
34
            f"Problematic UID: {self.problem_uid}, cycle: {self.cycled_uids}."
35
        )