blob: 1a65f365c98586ae5979ffb95aada7531ffa492a [file] [log] [blame]
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -07001# 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 Changa6413f52023-07-26 13:23:40 -070015from typing import List
David Pursehouse819827a2020-02-12 15:20:19 +090016
Jason Changa6413f52023-07-26 13:23:40 -070017
18class BaseRepoError(Exception):
19 """All repo specific exceptions derive from BaseRepoError."""
20
21
22class 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
30class 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
47class 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 Chang1a3612f2023-08-08 14:12:53 -070059class SilentRepoExitError(RepoExitError):
60 """RepoExitError that should no include CLI logging of issue/issues."""
61
62
Jason Changa6413f52023-07-26 13:23:40 -070063class ManifestParseError(RepoExitError):
Gavin Makea2e3302023-03-11 06:46:20 +000064 """Failed to parse the manifest file."""
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070065
David Pursehouse819827a2020-02-12 15:20:19 +090066
Mike Frysinger54133972021-03-01 21:38:08 -050067class ManifestInvalidRevisionError(ManifestParseError):
Gavin Makea2e3302023-03-11 06:46:20 +000068 """The revision value in a project is incorrect."""
Shawn O. Pearce559b8462009-03-02 12:56:08 -080069
David Pursehouse819827a2020-02-12 15:20:19 +090070
Mike Frysinger54133972021-03-01 21:38:08 -050071class ManifestInvalidPathError(ManifestParseError):
Gavin Makea2e3302023-03-11 06:46:20 +000072 """A path used in or is incorrect."""
Mike Frysinger04122b72019-07-31 23:32:58 -040073
David Pursehouse819827a2020-02-12 15:20:19 +090074
Jason Changa6413f52023-07-26 13:23:40 -070075class NoManifestException(RepoExitError):
Gavin Makea2e3302023-03-11 06:46:20 +000076 """The required manifest does not exist."""
David Pursehouse819827a2020-02-12 15:20:19 +090077
Jason Changa6413f52023-07-26 13:23:40 -070078 def __init__(self, path, reason, **kwargs):
79 super().__init__(path, reason, **kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +000080 self.path = path
81 self.reason = reason
Dan Sandler53e902a2014-03-09 13:20:02 -040082
Gavin Makea2e3302023-03-11 06:46:20 +000083 def __str__(self):
84 return self.reason
Conley Owens75ee0572012-11-15 17:33:11 -080085
David Pursehouse819827a2020-02-12 15:20:19 +090086
Jason Changa6413f52023-07-26 13:23:40 -070087class EditorError(RepoError):
Gavin Makea2e3302023-03-11 06:46:20 +000088 """Unspecified error from the user's text editor."""
David Pursehouse819827a2020-02-12 15:20:19 +090089
Jason Changa6413f52023-07-26 13:23:40 -070090 def __init__(self, reason, **kwargs):
91 super().__init__(reason, **kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +000092 self.reason = reason
Shawn O. Pearce54fccd72009-06-24 07:09:51 -070093
Gavin Makea2e3302023-03-11 06:46:20 +000094 def __str__(self):
95 return self.reason
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070096
David Pursehouse819827a2020-02-12 15:20:19 +090097
Jason Changa6413f52023-07-26 13:23:40 -070098class GitError(RepoError):
99 """Unspecified git related error."""
David Pursehouse819827a2020-02-12 15:20:19 +0900100
Jason Changa6413f52023-07-26 13:23:40 -0700101 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 Projectcf31fe92008-10-21 07:00:00 -0700105
Gavin Makea2e3302023-03-11 06:46:20 +0000106 def __str__(self):
Jason Changa6413f52023-07-26 13:23:40 -0700107 return self.message
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700108
David Pursehouse819827a2020-02-12 15:20:19 +0900109
Josip Sokcevicf7f9dd42024-10-03 20:32:04 +0000110class GitAuthError(RepoExitError):
111 """Cannot talk to remote due to auth issue."""
112
113
Jason Changa6413f52023-07-26 13:23:40 -0700114class UploadError(RepoError):
Gavin Makea2e3302023-03-11 06:46:20 +0000115 """A bundle upload to Gerrit did not succeed."""
David Pursehouse819827a2020-02-12 15:20:19 +0900116
Jason Changa6413f52023-07-26 13:23:40 -0700117 def __init__(self, reason, **kwargs):
118 super().__init__(reason, **kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +0000119 self.reason = reason
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700120
Gavin Makea2e3302023-03-11 06:46:20 +0000121 def __str__(self):
122 return self.reason
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700123
David Pursehouse819827a2020-02-12 15:20:19 +0900124
Jason Changa6413f52023-07-26 13:23:40 -0700125class DownloadError(RepoExitError):
Gavin Makea2e3302023-03-11 06:46:20 +0000126 """Cannot download a repository."""
David Pursehouse819827a2020-02-12 15:20:19 +0900127
Jason Changa6413f52023-07-26 13:23:40 -0700128 def __init__(self, reason, **kwargs):
129 super().__init__(reason, **kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +0000130 self.reason = reason
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700131
Gavin Makea2e3302023-03-11 06:46:20 +0000132 def __str__(self):
133 return self.reason
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700134
David Pursehouse819827a2020-02-12 15:20:19 +0900135
Jason Chang1a3612f2023-08-08 14:12:53 -0700136class InvalidArgumentsError(RepoExitError):
137 """Invalid command Arguments."""
138
139
Jason Changa6413f52023-07-26 13:23:40 -0700140class SyncError(RepoExitError):
141 """Cannot sync repo."""
142
143
144class UpdateManifestError(RepoExitError):
145 """Cannot update manifest."""
146
147
148class NoSuchProjectError(RepoExitError):
Gavin Makea2e3302023-03-11 06:46:20 +0000149 """A specified project does not exist in the work tree."""
David Pursehouse819827a2020-02-12 15:20:19 +0900150
Jason Changa6413f52023-07-26 13:23:40 -0700151 def __init__(self, name=None, **kwargs):
152 super().__init__(**kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +0000153 self.name = name
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700154
Gavin Makea2e3302023-03-11 06:46:20 +0000155 def __str__(self):
156 if self.name is None:
157 return "in current directory"
158 return self.name
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700159
Colin Cross5acde752012-03-28 20:15:45 -0700160
Jason Changa6413f52023-07-26 13:23:40 -0700161class InvalidProjectGroupsError(RepoExitError):
Gavin Makea2e3302023-03-11 06:46:20 +0000162 """A specified project is not suitable for the specified groups"""
David Pursehouse819827a2020-02-12 15:20:19 +0900163
Jason Changa6413f52023-07-26 13:23:40 -0700164 def __init__(self, name=None, **kwargs):
165 super().__init__(**kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +0000166 self.name = name
Colin Cross5acde752012-03-28 20:15:45 -0700167
Gavin Makea2e3302023-03-11 06:46:20 +0000168 def __str__(self):
169 if self.name is None:
170 return "in current directory"
171 return self.name
Colin Cross5acde752012-03-28 20:15:45 -0700172
David Pursehouse819827a2020-02-12 15:20:19 +0900173
Jason Changa6413f52023-07-26 13:23:40 -0700174class RepoChangedException(BaseRepoError):
Gavin Makea2e3302023-03-11 06:46:20 +0000175 """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 Pursehouse819827a2020-02-12 15:20:19 +0900179
Gavin Makea2e3302023-03-11 06:46:20 +0000180 def __init__(self, extra_args=None):
181 super().__init__(extra_args)
182 self.extra_args = extra_args or []
Doug Anderson37282b42011-03-04 11:54:18 -0800183
David Pursehouse819827a2020-02-12 15:20:19 +0900184
Jason Changa6413f52023-07-26 13:23:40 -0700185class HookError(RepoError):
Gavin Makea2e3302023-03-11 06:46:20 +0000186 """Thrown if a 'repo-hook' could not be run.
Doug Anderson37282b42011-03-04 11:54:18 -0800187
Gavin Makea2e3302023-03-11 06:46:20 +0000188 The common case is that the file wasn't present when we tried to run it.
189 """