Hide keyboard shortcuts

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

1# Copyright (C) 2018 Bloomberg LP 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# <http://www.apache.org/licenses/LICENSE-2.0> 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14 

15 

16""" 

17Exceptions 

18=========== 

19""" 

20 

21from enum import Enum 

22 

23 

24class BgdError(Exception): 

25 """ 

26 Base BuildGrid Error class for internal exceptions. 

27 """ 

28 

29 def __init__(self, message, *, detail=None, domain=None, reason=None): 

30 super().__init__(message) 

31 

32 # Additional detail and extra information 

33 self.detail = detail 

34 

35 # Domand and reason 

36 self.domain = domain 

37 self.reason = reason 

38 

39 

40class ErrorDomain(Enum): 

41 SERVER = 1 

42 BOT = 2 

43 

44 

45class ServerError(BgdError): 

46 def __init__(self, message, detail=None, reason=None): 

47 super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason) 

48 

49 

50class BotError(BgdError): 

51 def __init__(self, message, detail=None, reason=None): 

52 super().__init__(message, detail=detail, domain=ErrorDomain.BOT, reason=reason) 

53 

54 

55class CancelledError(BgdError): 

56 """The job was cancelled and any callers should be notified""" 

57 def __init__(self, message, detail=None, reason=None): 

58 super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason) 

59 self.last_response = None 

60 

61 

62class InvalidArgumentError(BgdError): 

63 """A bad argument was passed, such as a name which doesn't exist.""" 

64 def __init__(self, message, detail=None, reason=None): 

65 super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason) 

66 

67 

68class NotFoundError(BgdError): 

69 """Requested resource not found.""" 

70 def __init__(self, message, detail=None, reason=None): 

71 super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason) 

72 

73 

74class UpdateNotAllowedError(BgdError): 

75 """UpdateNotAllowedError error.""" 

76 def __init__(self, message, detail=None, reason=None): 

77 super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason) 

78 

79 

80class OutOfRangeError(BgdError): 

81 """ByteStream service read data out of range.""" 

82 def __init__(self, message, detail=None, reason=None): 

83 super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason) 

84 

85 

86class FailedPreconditionError(BgdError): 

87 """One or more errors occurred in setting up the action requested, such as 

88 a missing input or command or no worker being available. The client may be 

89 able to fix the errors and retry.""" 

90 def __init__(self, message, detail=None, reason=None): 

91 super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason) 

92 

93 

94class PermissionDeniedError(BgdError): 

95 """The caller does not have permission to execute the specified operation.""" 

96 def __init__(self, message, detail=None, reason=None): 

97 super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason) 

98 

99 

100class BotSessionError(BgdError): 

101 """Parent class of BotSession Exceptions""" 

102 

103 

104class BotSessionClosedError(BotSessionError): 

105 """The requested BotSession has been closed recently.""" 

106 def __init__(self, message, detail=None, reason=None): 

107 super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason) 

108 

109 

110class UnknownBotSessionError(BotSessionError): 

111 """Buildgrid does not know the requested BotSession.""" 

112 def __init__(self, message, detail=None, reason=None): 

113 super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason) 

114 

115 

116class BotSessionMismatchError(BotSessionError): 

117 """The BotSession details don't match those in BuildGrid's records.""" 

118 def __init__(self, message, detail=None, reason=None): 

119 super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason) 

120 

121 

122class DuplicateBotSessionError(BotSessionError): 

123 """The bot with this ID already has a BotSession.""" 

124 def __init__(self, message, detail=None, reason=None): 

125 super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason) 

126 

127 

128class DatabaseError(BgdError): 

129 """BuildGrid encountered a database error""" 

130 def __init__(self, message, detail=None, reason=None): 

131 super().__init__(message, detail=detail, domain=ErrorDomain.SERVER, reason=reason)