The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | # Copyright (C) 2008 The Android Open Source Project |
| 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 | |
Jason Chang | a6413f5 | 2023-07-26 13:23:40 -0700 | [diff] [blame] | 15 | from typing import List |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 16 | |
Jason Chang | a6413f5 | 2023-07-26 13:23:40 -0700 | [diff] [blame] | 17 | |
| 18 | class BaseRepoError(Exception): |
| 19 | """All repo specific exceptions derive from BaseRepoError.""" |
| 20 | |
| 21 | |
| 22 | class RepoError(BaseRepoError): |
| 23 | """Exceptions thrown inside repo that can be handled.""" |
| 24 | |
| 25 | def __init__(self, *args, project: str = None) -> None: |
| 26 | super().__init__(*args) |
| 27 | self.project = project |
| 28 | |
| 29 | |
| 30 | class RepoExitError(BaseRepoError): |
| 31 | """Exception thrown that result in termination of repo program. |
| 32 | - Should only be handled in main.py |
| 33 | """ |
| 34 | |
| 35 | def __init__( |
| 36 | self, |
| 37 | *args, |
| 38 | exit_code: int = 1, |
| 39 | aggregate_errors: List[Exception] = None, |
| 40 | **kwargs, |
| 41 | ) -> None: |
| 42 | super().__init__(*args, **kwargs) |
| 43 | self.exit_code = exit_code |
| 44 | self.aggregate_errors = aggregate_errors |
| 45 | |
| 46 | |
| 47 | class RepoUnhandledExceptionError(RepoExitError): |
| 48 | """Exception that maintains error as reason for program exit.""" |
| 49 | |
| 50 | def __init__( |
| 51 | self, |
| 52 | error: BaseException, |
| 53 | **kwargs, |
| 54 | ) -> None: |
| 55 | super().__init__(error, **kwargs) |
| 56 | self.error = error |
| 57 | |
| 58 | |
Jason Chang | 1a3612f | 2023-08-08 14:12:53 -0700 | [diff] [blame] | 59 | class SilentRepoExitError(RepoExitError): |
| 60 | """RepoExitError that should no include CLI logging of issue/issues.""" |
| 61 | |
| 62 | |
Jason Chang | a6413f5 | 2023-07-26 13:23:40 -0700 | [diff] [blame] | 63 | class ManifestParseError(RepoExitError): |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 64 | """Failed to parse the manifest file.""" |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 65 | |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 66 | |
Mike Frysinger | 5413397 | 2021-03-01 21:38:08 -0500 | [diff] [blame] | 67 | class ManifestInvalidRevisionError(ManifestParseError): |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 68 | """The revision value in a project is incorrect.""" |
Shawn O. Pearce | 559b846 | 2009-03-02 12:56:08 -0800 | [diff] [blame] | 69 | |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 70 | |
Mike Frysinger | 5413397 | 2021-03-01 21:38:08 -0500 | [diff] [blame] | 71 | class ManifestInvalidPathError(ManifestParseError): |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 72 | """A path used in or is incorrect.""" |
Mike Frysinger | 04122b7 | 2019-07-31 23:32:58 -0400 | [diff] [blame] | 73 | |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 74 | |
Jason Chang | a6413f5 | 2023-07-26 13:23:40 -0700 | [diff] [blame] | 75 | class NoManifestException(RepoExitError): |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 76 | """The required manifest does not exist.""" |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 77 | |
Jason Chang | a6413f5 | 2023-07-26 13:23:40 -0700 | [diff] [blame] | 78 | def __init__(self, path, reason, **kwargs): |
| 79 | super().__init__(path, reason, **kwargs) |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 80 | self.path = path |
| 81 | self.reason = reason |
Dan Sandler | 53e902a | 2014-03-09 13:20:02 -0400 | [diff] [blame] | 82 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 83 | def __str__(self): |
| 84 | return self.reason |
Conley Owens | 75ee057 | 2012-11-15 17:33:11 -0800 | [diff] [blame] | 85 | |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 86 | |
Jason Chang | a6413f5 | 2023-07-26 13:23:40 -0700 | [diff] [blame] | 87 | class EditorError(RepoError): |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 88 | """Unspecified error from the user's text editor.""" |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 89 | |
Jason Chang | a6413f5 | 2023-07-26 13:23:40 -0700 | [diff] [blame] | 90 | def __init__(self, reason, **kwargs): |
| 91 | super().__init__(reason, **kwargs) |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 92 | self.reason = reason |
Shawn O. Pearce | 54fccd7 | 2009-06-24 07:09:51 -0700 | [diff] [blame] | 93 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 94 | def __str__(self): |
| 95 | return self.reason |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 96 | |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 97 | |
Jason Chang | a6413f5 | 2023-07-26 13:23:40 -0700 | [diff] [blame] | 98 | class GitError(RepoError): |
| 99 | """Unspecified git related error.""" |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 100 | |
Jason Chang | a6413f5 | 2023-07-26 13:23:40 -0700 | [diff] [blame] | 101 | def __init__(self, message, command_args=None, **kwargs): |
| 102 | super().__init__(message, **kwargs) |
| 103 | self.message = message |
| 104 | self.command_args = command_args |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 105 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 106 | def __str__(self): |
Jason Chang | a6413f5 | 2023-07-26 13:23:40 -0700 | [diff] [blame] | 107 | return self.message |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 108 | |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 109 | |
Josip Sokcevic | f7f9dd4 | 2024-10-03 20:32:04 +0000 | [diff] [blame] | 110 | class GitAuthError(RepoExitError): |
| 111 | """Cannot talk to remote due to auth issue.""" |
| 112 | |
| 113 | |
Jason Chang | a6413f5 | 2023-07-26 13:23:40 -0700 | [diff] [blame] | 114 | class UploadError(RepoError): |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 115 | """A bundle upload to Gerrit did not succeed.""" |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 116 | |
Jason Chang | a6413f5 | 2023-07-26 13:23:40 -0700 | [diff] [blame] | 117 | def __init__(self, reason, **kwargs): |
| 118 | super().__init__(reason, **kwargs) |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 119 | self.reason = reason |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 120 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 121 | def __str__(self): |
| 122 | return self.reason |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 123 | |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 124 | |
Jason Chang | a6413f5 | 2023-07-26 13:23:40 -0700 | [diff] [blame] | 125 | class DownloadError(RepoExitError): |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 126 | """Cannot download a repository.""" |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 127 | |
Jason Chang | a6413f5 | 2023-07-26 13:23:40 -0700 | [diff] [blame] | 128 | def __init__(self, reason, **kwargs): |
| 129 | super().__init__(reason, **kwargs) |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 130 | self.reason = reason |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 131 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 132 | def __str__(self): |
| 133 | return self.reason |
Shawn O. Pearce | f322b9a | 2011-09-19 14:50:58 -0700 | [diff] [blame] | 134 | |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 135 | |
Jason Chang | 1a3612f | 2023-08-08 14:12:53 -0700 | [diff] [blame] | 136 | class InvalidArgumentsError(RepoExitError): |
| 137 | """Invalid command Arguments.""" |
| 138 | |
| 139 | |
Jason Chang | a6413f5 | 2023-07-26 13:23:40 -0700 | [diff] [blame] | 140 | class SyncError(RepoExitError): |
| 141 | """Cannot sync repo.""" |
| 142 | |
| 143 | |
| 144 | class UpdateManifestError(RepoExitError): |
| 145 | """Cannot update manifest.""" |
| 146 | |
| 147 | |
| 148 | class NoSuchProjectError(RepoExitError): |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 149 | """A specified project does not exist in the work tree.""" |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 150 | |
Jason Chang | a6413f5 | 2023-07-26 13:23:40 -0700 | [diff] [blame] | 151 | def __init__(self, name=None, **kwargs): |
| 152 | super().__init__(**kwargs) |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 153 | self.name = name |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 154 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 155 | def __str__(self): |
| 156 | if self.name is None: |
| 157 | return "in current directory" |
| 158 | return self.name |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 159 | |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 160 | |
Jason Chang | a6413f5 | 2023-07-26 13:23:40 -0700 | [diff] [blame] | 161 | class InvalidProjectGroupsError(RepoExitError): |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 162 | """A specified project is not suitable for the specified groups""" |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 163 | |
Jason Chang | a6413f5 | 2023-07-26 13:23:40 -0700 | [diff] [blame] | 164 | def __init__(self, name=None, **kwargs): |
| 165 | super().__init__(**kwargs) |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 166 | self.name = name |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 167 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 168 | def __str__(self): |
| 169 | if self.name is None: |
| 170 | return "in current directory" |
| 171 | return self.name |
Colin Cross | 5acde75 | 2012-03-28 20:15:45 -0700 | [diff] [blame] | 172 | |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 173 | |
Jason Chang | a6413f5 | 2023-07-26 13:23:40 -0700 | [diff] [blame] | 174 | class RepoChangedException(BaseRepoError): |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 175 | """Thrown if 'repo sync' results in repo updating its internal |
| 176 | repo or manifest repositories. In this special case we must |
| 177 | use exec to re-execute repo with the new code and manifest. |
| 178 | """ |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 179 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 180 | def __init__(self, extra_args=None): |
| 181 | super().__init__(extra_args) |
| 182 | self.extra_args = extra_args or [] |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 183 | |
David Pursehouse | 819827a | 2020-02-12 15:20:19 +0900 | [diff] [blame] | 184 | |
Jason Chang | a6413f5 | 2023-07-26 13:23:40 -0700 | [diff] [blame] | 185 | class HookError(RepoError): |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 186 | """Thrown if a 'repo-hook' could not be run. |
Doug Anderson | 37282b4 | 2011-03-04 11:54:18 -0800 | [diff] [blame] | 187 | |
Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 188 | The common case is that the file wasn't present when we tried to run it. |
| 189 | """ |