Coverage for src/nendo/schema/exception.py: 61%

57 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-11-14 13:48 +0100

1"""Schemas for common typed of nendo objects.""" 

2from __future__ import annotations 

3 

4 

5class NendoError(Exception): 

6 """Base class for nendo errors.""" 

7 

8 def __init__(self, message): # noqa: D107 

9 super().__init__(message) 

10 self.message = message 

11 

12 

13class NendoIdError(NendoError): 

14 """Nendo error with an additional details field.""" 

15 

16 def __init__(self, message, target_id): # noqa: D107 

17 super().__init__(message) 

18 self.target_id = target_id 

19 

20 

21class NendoPluginError(NendoError): 

22 """Generic Plugin Error. 

23 

24 Any custom plugin error should inherit from this. 

25 """ 

26 

27 

28class NendoPluginConfigError(NendoPluginError): 

29 """Error related to the (mis)configuration of a plugin.""" 

30 

31 

32class NendoPluginLoadingError(NendoPluginError): 

33 """Error related to loading of a plugin.""" 

34 

35 

36class NendoPluginRuntimeError(NendoPluginError): 

37 """Generic plugin runtime error.""" 

38 

39 

40class NendoLibraryError(NendoError): 

41 """Generic library error. 

42 

43 All other library error inherit from this. 

44 """ 

45 

46 

47class NendoStorageError(NendoLibraryError): 

48 """Generic storage error.""" 

49 

50 

51class NendoResourceError(NendoError): 

52 """Error related to a Nendo resource.""" 

53 

54 def __init__(self, message, src): # noqa: D107 

55 super().__init__(message) 

56 self.src = src 

57 

58 def __str__(self): 

59 return f"Error with resource {self.src}. Details: {self.message}" 

60 

61 

62class NendoLibraryIdError(NendoLibraryError): 

63 """A library error that refers to an item with a specified id.""" 

64 

65 def __init__(self, message, target_id): # noqa: D107 

66 super().__init__(message) 

67 self.target_id = target_id 

68 

69 

70class NendoUserNotFoundError(NendoLibraryIdError): 

71 """Error raised if a user was accessed that does not exist.""" 

72 

73 def __str__(self): 

74 return f"User with ID {self.target_id} not found." 

75 

76 

77class NendoTrackNotFoundError(NendoLibraryIdError): 

78 """Error raised if a track was accessed that does not exist.""" 

79 

80 def __str__(self): 

81 return f"Track with ID {self.target_id} not found." 

82 

83 

84class NendoBlobNotFoundError(NendoLibraryIdError): 

85 """Error raised if a blob was accessed that does not exist.""" 

86 

87 def __str__(self): 

88 return f"Blob with ID {self.target_id} not found." 

89 

90 

91class NendoCollectionNotFoundError(NendoLibraryIdError): 

92 """Error raised if a collection was accessed that does not exist.""" 

93 

94 def __str__(self): 

95 return f"Collection with ID {self.target_id} not found." 

96 

97 

98class NendoRelationshipNotFoundError(NendoLibraryError): 

99 """Error raised if a relationship does not exist beween two IDs.""" 

100 

101 def __init__(self, message, source_id, target_id): # noqa: D107 

102 super().__init__(message) 

103 self.source_id = source_id 

104 self.target_id = target_id 

105 

106 def __str__(self): 

107 return f"Relationship between {self.source_id} and {self.target_id} not found." 

108 

109 

110class NendoPluginDataNotFoundError(NendoLibraryIdError): 

111 """Error raised if a plugin data was accessed that does not exist.""" 

112 

113 def __str__(self): 

114 return f"Plugin data with ID {self.target_id} not found." 

115 

116 

117class NendoFileFormatError(NendoLibraryError): 

118 """Error raised if there is an error with the format of a processed file.""" 

119 

120 

121class NendoMalformedIDError(NendoLibraryIdError): 

122 """Error raised if the given ID is malformed / does not represent a valid UUID.""" 

123 

124 def __str__(self): 

125 return f"Malformed ID {self.target_id}." 

126 

127 

128class NendoBucketNotFoundError(NendoStorageError): 

129 """A library error that refers to an item with a specified id.""" 

130 

131 def __init__(self, message, bucket_name): # noqa: D107 

132 super().__init__(message) 

133 self.bucket_name = bucket_name 

134 

135 def __str__(self): 

136 return f"Bucket with name {self.bucket_name} not found."