Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | # 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. |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 4 | |
| 5 | """Exception classes used throughout monorail. |
| 6 | """ |
| 7 | from __future__ import print_function |
| 8 | from __future__ import division |
| 9 | from __future__ import absolute_import |
| 10 | |
| 11 | |
| 12 | class 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 | |
| 50 | class Error(Exception): |
| 51 | """Base class for errors from this module.""" |
| 52 | pass |
| 53 | |
| 54 | |
| 55 | class ActionNotSupported(Error): |
| 56 | """The user is trying to do something we do not support.""" |
| 57 | pass |
| 58 | |
| 59 | |
| 60 | class InputException(Error): |
| 61 | """Error in user input processing.""" |
| 62 | pass |
| 63 | |
| 64 | |
| 65 | class ProjectAlreadyExists(Error): |
| 66 | """Tried to create a project that already exists.""" |
| 67 | |
| 68 | |
| 69 | class FieldDefAlreadyExists(Error): |
| 70 | """Tried to create a custom field that already exists.""" |
| 71 | |
| 72 | |
| 73 | class ComponentDefAlreadyExists(Error): |
| 74 | """Tried to create a component that already exists.""" |
| 75 | |
| 76 | |
| 77 | class NoSuchProjectException(Error): |
| 78 | """No project with the specified name exists.""" |
| 79 | pass |
| 80 | |
| 81 | |
| 82 | class NoSuchTemplateException(Error): |
| 83 | """No template with the specified name exists.""" |
| 84 | pass |
| 85 | |
| 86 | |
| 87 | class NoSuchUserException(Error): |
| 88 | """No user with the specified name exists.""" |
| 89 | pass |
| 90 | |
| 91 | |
| 92 | class NoSuchIssueException(Error): |
| 93 | """The requested issue was not found.""" |
| 94 | pass |
| 95 | |
| 96 | |
| 97 | class NoSuchAttachmentException(Error): |
| 98 | """The requested attachment was not found.""" |
| 99 | pass |
| 100 | |
| 101 | |
| 102 | class NoSuchCommentException(Error): |
| 103 | """The requested comment was not found.""" |
| 104 | pass |
| 105 | |
| 106 | |
| 107 | class NoSuchAmendmentException(Error): |
| 108 | """The requested amendment was not found.""" |
| 109 | pass |
| 110 | |
| 111 | |
| 112 | class NoSuchComponentException(Error): |
| 113 | """No component with the specified name exists.""" |
| 114 | pass |
| 115 | |
| 116 | |
| 117 | class InvalidComponentNameException(Error): |
| 118 | """The component name is invalid.""" |
| 119 | pass |
| 120 | |
| 121 | |
| 122 | class InvalidHotlistException(Error): |
| 123 | """The specified hotlist is invalid.""" |
| 124 | pass |
| 125 | |
| 126 | |
| 127 | class NoSuchFieldDefException(Error): |
| 128 | """No field def for specified project exists.""" |
| 129 | pass |
| 130 | |
| 131 | |
| 132 | class InvalidFieldTypeException(Error): |
| 133 | """Expected field type and actual field type do not match.""" |
| 134 | pass |
| 135 | |
| 136 | |
| 137 | class NoSuchIssueApprovalException(Error): |
| 138 | """The requested approval for the issue was not found.""" |
| 139 | pass |
| 140 | |
| 141 | |
| 142 | class CircularGroupException(Error): |
| 143 | """Circular nested group exception.""" |
| 144 | pass |
| 145 | |
| 146 | |
| 147 | class GroupExistsException(Error): |
| 148 | """Group already exists exception.""" |
| 149 | pass |
| 150 | |
| 151 | |
| 152 | class NoSuchGroupException(Error): |
| 153 | """Requested group was not found exception.""" |
| 154 | pass |
| 155 | |
| 156 | |
| 157 | class 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 | |
| 171 | class PageTokenException(Error): |
| 172 | """Incorrect page tokens.""" |
| 173 | pass |
| 174 | |
| 175 | |
| 176 | class FilterRuleException(Error): |
| 177 | """Violates a filter rule that should show error.""" |
| 178 | pass |
| 179 | |
| 180 | |
| 181 | class OverAttachmentQuota(Error): |
| 182 | """Project will exceed quota if the current operation is allowed.""" |
| 183 | pass |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 184 | |
| 185 | |
| 186 | class RedirectException(Error): |
| 187 | """Page need to Redirect to new url.""" |
| 188 | pass |