blob: 36bc212977ee3fa53a5140a208e297e33004c2c5 [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 Chang8914b1f2023-05-26 12:44:50 -0700114class GitcUnsupportedError(RepoExitError):
115 """Gitc no longer supported."""
116
117
Jason Changa6413f52023-07-26 13:23:40 -0700118class UploadError(RepoError):
Gavin Makea2e3302023-03-11 06:46:20 +0000119 """A bundle upload to Gerrit did not succeed."""
David Pursehouse819827a2020-02-12 15:20:19 +0900120
Jason Changa6413f52023-07-26 13:23:40 -0700121 def __init__(self, reason, **kwargs):
122 super().__init__(reason, **kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +0000123 self.reason = reason
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700124
Gavin Makea2e3302023-03-11 06:46:20 +0000125 def __str__(self):
126 return self.reason
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700127
David Pursehouse819827a2020-02-12 15:20:19 +0900128
Jason Changa6413f52023-07-26 13:23:40 -0700129class DownloadError(RepoExitError):
Gavin Makea2e3302023-03-11 06:46:20 +0000130 """Cannot download a repository."""
David Pursehouse819827a2020-02-12 15:20:19 +0900131
Jason Changa6413f52023-07-26 13:23:40 -0700132 def __init__(self, reason, **kwargs):
133 super().__init__(reason, **kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +0000134 self.reason = reason
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700135
Gavin Makea2e3302023-03-11 06:46:20 +0000136 def __str__(self):
137 return self.reason
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700138
David Pursehouse819827a2020-02-12 15:20:19 +0900139
Jason Chang1a3612f2023-08-08 14:12:53 -0700140class InvalidArgumentsError(RepoExitError):
141 """Invalid command Arguments."""
142
143
Jason Changa6413f52023-07-26 13:23:40 -0700144class SyncError(RepoExitError):
145 """Cannot sync repo."""
146
147
148class UpdateManifestError(RepoExitError):
149 """Cannot update manifest."""
150
151
152class NoSuchProjectError(RepoExitError):
Gavin Makea2e3302023-03-11 06:46:20 +0000153 """A specified project does not exist in the work tree."""
David Pursehouse819827a2020-02-12 15:20:19 +0900154
Jason Changa6413f52023-07-26 13:23:40 -0700155 def __init__(self, name=None, **kwargs):
156 super().__init__(**kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +0000157 self.name = name
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700158
Gavin Makea2e3302023-03-11 06:46:20 +0000159 def __str__(self):
160 if self.name is None:
161 return "in current directory"
162 return self.name
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700163
Colin Cross5acde752012-03-28 20:15:45 -0700164
Jason Changa6413f52023-07-26 13:23:40 -0700165class InvalidProjectGroupsError(RepoExitError):
Gavin Makea2e3302023-03-11 06:46:20 +0000166 """A specified project is not suitable for the specified groups"""
David Pursehouse819827a2020-02-12 15:20:19 +0900167
Jason Changa6413f52023-07-26 13:23:40 -0700168 def __init__(self, name=None, **kwargs):
169 super().__init__(**kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +0000170 self.name = name
Colin Cross5acde752012-03-28 20:15:45 -0700171
Gavin Makea2e3302023-03-11 06:46:20 +0000172 def __str__(self):
173 if self.name is None:
174 return "in current directory"
175 return self.name
Colin Cross5acde752012-03-28 20:15:45 -0700176
David Pursehouse819827a2020-02-12 15:20:19 +0900177
Jason Changa6413f52023-07-26 13:23:40 -0700178class RepoChangedException(BaseRepoError):
Gavin Makea2e3302023-03-11 06:46:20 +0000179 """Thrown if 'repo sync' results in repo updating its internal
180 repo or manifest repositories. In this special case we must
181 use exec to re-execute repo with the new code and manifest.
182 """
David Pursehouse819827a2020-02-12 15:20:19 +0900183
Gavin Makea2e3302023-03-11 06:46:20 +0000184 def __init__(self, extra_args=None):
185 super().__init__(extra_args)
186 self.extra_args = extra_args or []
Doug Anderson37282b42011-03-04 11:54:18 -0800187
David Pursehouse819827a2020-02-12 15:20:19 +0900188
Jason Changa6413f52023-07-26 13:23:40 -0700189class HookError(RepoError):
Gavin Makea2e3302023-03-11 06:46:20 +0000190 """Thrown if a 'repo-hook' could not be run.
Doug Anderson37282b42011-03-04 11:54:18 -0800191
Gavin Makea2e3302023-03-11 06:46:20 +0000192 The common case is that the file wasn't present when we tried to run it.
193 """