Bases: Exception
Type error with message, followed by type suggestion, chosen by fuzzy matching
(out of 'choices' arg passed in init).
Attributes:
message -- explanation of the error
Source code in common/exceptions/factory_exceptions.py
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 | class UnknownTypeException(Exception):
"""Type error with message, followed by type suggestion, chosen by fuzzy matching
(out of 'choices' arg passed in __init__).
Attributes:
message -- explanation of the error
"""
def __init__(self, unknown_type: str, choices: List, message: str = None):
message = message or f"Unknown object type: {unknown_type} in configuration. valid types are: {choices}"
err_msg_tip = ""
if isinstance(unknown_type, str):
choice, score, _ = process.extractOne(unknown_type, choices, scorer=fuzz.WRatio)
if score > 70:
err_msg_tip = f"\n Did you mean: {choice}?"
self.message = message + err_msg_tip
super().__init__(self.message)
|