Coverage for bugscpp/errors/internal.py : 79%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import argparse
2import json
3from dataclasses import fields
4from typing import Dict
6from errors.common.exception import DppError
9class DppInternalError(DppError):
10 pass
13class DppCaseExpressionInternalError(DppInternalError):
14 def __init__(self, namespace: argparse.Namespace):
15 super().__init__(f"namespace={namespace}")
16 self.namespace: argparse.Namespace = namespace
19class DppCommandListInternalError(DppInternalError):
20 def __init__(self):
21 super().__init__(f"{self.__class__} object does not support item assignment")
24class DppTaxonomyInitInternalError(DppInternalError):
25 def __init__(self, key: str, data_name: str):
26 super().__init__(
27 f"Cannot initialize Taxonomy. {key} does not exist in {data_name}."
28 " Please check meta.json of Taxonomy"
29 )
30 self.key: str = key
31 self.data_name = data_name
34class DppMetaDataInitKeyError(DppInternalError):
35 def __init__(self, value: Dict):
36 # Put here to avoid cyclic imports.
37 from taxonomy import Command
39 super().__init__(
40 "Cannot initialize Metadata.\n"
41 f"{json.dumps(value, indent=2)} is ill-formed."
42 " Please check your config.\n"
43 f"Required keys are [{', '.join(f.name for f in fields(Command))}], "
44 f"but got [{', '.join(k for k in value)}]."
45 )
46 self.value: Dict = value
49class DppMetaDataInitTypeError(DppInternalError):
50 def __init__(self, value: Dict):
51 # Put here to avoid cyclic imports.
52 from taxonomy import CommandType
54 super().__init__(
55 "Cannot initialize Metadata.\n"
56 f"{json.dumps(value, indent=2)} is ill-formed."
57 " Please check your config\n"
58 f"Valid enum values are [{', '.join(e.name for e in CommandType)}], "
59 f"but got '{value['type']}'."
60 )
61 self.value: Dict = value