Debian Codegraph @

src/nitrokey/trussed/_bootloader/lpc55_upload/exceptions.py

raw
1 #!/usr/bin/env python
2 # -*- coding: UTF-8 -*-
3 #
4 # Copyright 2019-2024 NXP
5 #
6 # SPDX-License-Identifier: BSD-3-Clause
7
8 """Base for SPSDK exceptions."""
9
10 from typing import Optional
11
12 #######################################################################
13 # # Secure Provisioning SDK Exceptions
14 #######################################################################
15
16
17 class SPSDKError(Exception):
18 """Secure Provisioning SDK Base Exception."""
19
20 fmt = "SPSDK: {description}"
21
22 def __init__(self, desc: Optional[str] = None) -> None:
23 """Initialize the base SPSDK Exception."""
24 super().__init__()
25 self.description = desc
26
27 def __str__(self) -> str:
28 return self.fmt.format(description=self.description or "Unknown Error")
29
30
31 class SPSDKKeyError(SPSDKError, KeyError):
32 """SPSDK standard key error."""
33
34
35 class SPSDKValueError(SPSDKError, ValueError):
36 """SPSDK standard value error."""
37
38
39 class SPSDKTypeError(SPSDKError, TypeError):
40 """SPSDK standard type error."""
41
42
43 class SPSDKAttributeError(SPSDKError, AttributeError):
44 """SPSDK standard attribute error."""
45
46
47 class SPSDKConnectionError(SPSDKError, ConnectionError):
48 """SPSDK standard connection error."""