blob: 2024f510986f7d4a6fbaac862688d1cbf284be3b [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# Copyright 2017 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
Copybara854996b2021-09-07 19:36:02 +00004
5"""Exception classes used throughout monorail.
6"""
7from __future__ import print_function
8from __future__ import division
9from __future__ import absolute_import
10
11
12class ErrorAggregator():
13 """Class for holding errors and raising an exception for many."""
14
15 def __init__(self, exc_type):
16 # type: (type) -> None
17 self.exc_type = exc_type
18 self.error_messages = []
19
20 def __enter__(self):
21 return self
22
23 def __exit__(self, exc_type, exc_value, exc_traceback):
24 # If no exceptions were raised within the context, we check
25 # if any error messages were accumulated that we should raise
26 # an exception for.
27 if exc_type == None:
28 self.RaiseIfErrors()
29 # If there were exceptions raised within the context, we do
30 # nothing to suppress them.
31
32 def AddErrorMessage(self, message, *args, **kwargs):
33 # type: (str, *Any, **Any) -> None
34 """Add a new error message.
35
36 Args:
37 message: An error message, to be formatted using *args and **kwargs.
38 *args: passed in to str.format.
39 **kwargs: passed in to str.format.
40 """
41 self.error_messages.append(message.format(*args, **kwargs))
42
43 def RaiseIfErrors(self):
44 # type: () -> None
45 """If there are errors, raise one exception."""
46 if self.error_messages:
47 raise self.exc_type("\n".join(self.error_messages))
48
49
50class Error(Exception):
51 """Base class for errors from this module."""
52 pass
53
54
55class ActionNotSupported(Error):
56 """The user is trying to do something we do not support."""
57 pass
58
59
60class InputException(Error):
61 """Error in user input processing."""
62 pass
63
64
65class ProjectAlreadyExists(Error):
66 """Tried to create a project that already exists."""
67
68
69class FieldDefAlreadyExists(Error):
70 """Tried to create a custom field that already exists."""
71
72
73class ComponentDefAlreadyExists(Error):
74 """Tried to create a component that already exists."""
75
76
77class NoSuchProjectException(Error):
78 """No project with the specified name exists."""
79 pass
80
81
82class NoSuchTemplateException(Error):
83 """No template with the specified name exists."""
84 pass
85
86
87class NoSuchUserException(Error):
88 """No user with the specified name exists."""
89 pass
90
91
92class NoSuchIssueException(Error):
93 """The requested issue was not found."""
94 pass
95
96
97class NoSuchAttachmentException(Error):
98 """The requested attachment was not found."""
99 pass
100
101
102class NoSuchCommentException(Error):
103 """The requested comment was not found."""
104 pass
105
106
107class NoSuchAmendmentException(Error):
108 """The requested amendment was not found."""
109 pass
110
111
112class NoSuchComponentException(Error):
113 """No component with the specified name exists."""
114 pass
115
116
117class InvalidComponentNameException(Error):
118 """The component name is invalid."""
119 pass
120
121
122class InvalidHotlistException(Error):
123 """The specified hotlist is invalid."""
124 pass
125
126
127class NoSuchFieldDefException(Error):
128 """No field def for specified project exists."""
129 pass
130
131
132class InvalidFieldTypeException(Error):
133 """Expected field type and actual field type do not match."""
134 pass
135
136
137class NoSuchIssueApprovalException(Error):
138 """The requested approval for the issue was not found."""
139 pass
140
141
142class CircularGroupException(Error):
143 """Circular nested group exception."""
144 pass
145
146
147class GroupExistsException(Error):
148 """Group already exists exception."""
149 pass
150
151
152class NoSuchGroupException(Error):
153 """Requested group was not found exception."""
154 pass
155
156
157class InvalidExternalIssueReference(Error):
158 """Improperly formatted external issue reference.
159
160 External issue references must be of the form:
161
162 $tracker_shortname/$tracker_specific_id
163
164 For example, issuetracker.google.com issues:
165
166 b/123456789
167 """
168 pass
169
170
171class PageTokenException(Error):
172 """Incorrect page tokens."""
173 pass
174
175
176class FilterRuleException(Error):
177 """Violates a filter rule that should show error."""
178 pass
179
180
181class OverAttachmentQuota(Error):
182 """Project will exceed quota if the current operation is allowed."""
183 pass
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +0100184
185
186class RedirectException(Error):
187 """Page need to Redirect to new url."""
188 pass