blob: ed4a90b787c3d6f4b7e2fb26053ea2bc57225d91 [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
59class ManifestParseError(RepoExitError):
Gavin Makea2e3302023-03-11 06:46:20 +000060 """Failed to parse the manifest file."""
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070061
David Pursehouse819827a2020-02-12 15:20:19 +090062
Mike Frysinger54133972021-03-01 21:38:08 -050063class ManifestInvalidRevisionError(ManifestParseError):
Gavin Makea2e3302023-03-11 06:46:20 +000064 """The revision value in a project is incorrect."""
Shawn O. Pearce559b8462009-03-02 12:56:08 -080065
David Pursehouse819827a2020-02-12 15:20:19 +090066
Mike Frysinger54133972021-03-01 21:38:08 -050067class ManifestInvalidPathError(ManifestParseError):
Gavin Makea2e3302023-03-11 06:46:20 +000068 """A path used in <copyfile> or <linkfile> is incorrect."""
Mike Frysinger04122b72019-07-31 23:32:58 -040069
David Pursehouse819827a2020-02-12 15:20:19 +090070
Jason Changa6413f52023-07-26 13:23:40 -070071class NoManifestException(RepoExitError):
Gavin Makea2e3302023-03-11 06:46:20 +000072 """The required manifest does not exist."""
David Pursehouse819827a2020-02-12 15:20:19 +090073
Jason Changa6413f52023-07-26 13:23:40 -070074 def __init__(self, path, reason, **kwargs):
75 super().__init__(path, reason, **kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +000076 self.path = path
77 self.reason = reason
Dan Sandler53e902a2014-03-09 13:20:02 -040078
Gavin Makea2e3302023-03-11 06:46:20 +000079 def __str__(self):
80 return self.reason
Conley Owens75ee0572012-11-15 17:33:11 -080081
David Pursehouse819827a2020-02-12 15:20:19 +090082
Jason Changa6413f52023-07-26 13:23:40 -070083class EditorError(RepoError):
Gavin Makea2e3302023-03-11 06:46:20 +000084 """Unspecified error from the user's text editor."""
David Pursehouse819827a2020-02-12 15:20:19 +090085
Jason Changa6413f52023-07-26 13:23:40 -070086 def __init__(self, reason, **kwargs):
87 super().__init__(reason, **kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +000088 self.reason = reason
Shawn O. Pearce54fccd72009-06-24 07:09:51 -070089
Gavin Makea2e3302023-03-11 06:46:20 +000090 def __str__(self):
91 return self.reason
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -070092
David Pursehouse819827a2020-02-12 15:20:19 +090093
Jason Changa6413f52023-07-26 13:23:40 -070094class GitError(RepoError):
95 """Unspecified git related error."""
David Pursehouse819827a2020-02-12 15:20:19 +090096
Jason Changa6413f52023-07-26 13:23:40 -070097 def __init__(self, message, command_args=None, **kwargs):
98 super().__init__(message, **kwargs)
99 self.message = message
100 self.command_args = command_args
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700101
Gavin Makea2e3302023-03-11 06:46:20 +0000102 def __str__(self):
Jason Changa6413f52023-07-26 13:23:40 -0700103 return self.message
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700104
David Pursehouse819827a2020-02-12 15:20:19 +0900105
Jason Changa6413f52023-07-26 13:23:40 -0700106class UploadError(RepoError):
Gavin Makea2e3302023-03-11 06:46:20 +0000107 """A bundle upload to Gerrit did not succeed."""
David Pursehouse819827a2020-02-12 15:20:19 +0900108
Jason Changa6413f52023-07-26 13:23:40 -0700109 def __init__(self, reason, **kwargs):
110 super().__init__(reason, **kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +0000111 self.reason = reason
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700112
Gavin Makea2e3302023-03-11 06:46:20 +0000113 def __str__(self):
114 return self.reason
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700115
David Pursehouse819827a2020-02-12 15:20:19 +0900116
Jason Changa6413f52023-07-26 13:23:40 -0700117class DownloadError(RepoExitError):
Gavin Makea2e3302023-03-11 06:46:20 +0000118 """Cannot download a repository."""
David Pursehouse819827a2020-02-12 15:20:19 +0900119
Jason Changa6413f52023-07-26 13:23:40 -0700120 def __init__(self, reason, **kwargs):
121 super().__init__(reason, **kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +0000122 self.reason = reason
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700123
Gavin Makea2e3302023-03-11 06:46:20 +0000124 def __str__(self):
125 return self.reason
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700126
David Pursehouse819827a2020-02-12 15:20:19 +0900127
Jason Changa6413f52023-07-26 13:23:40 -0700128class SyncError(RepoExitError):
129 """Cannot sync repo."""
130
131
132class UpdateManifestError(RepoExitError):
133 """Cannot update manifest."""
134
135
136class NoSuchProjectError(RepoExitError):
Gavin Makea2e3302023-03-11 06:46:20 +0000137 """A specified project does not exist in the work tree."""
David Pursehouse819827a2020-02-12 15:20:19 +0900138
Jason Changa6413f52023-07-26 13:23:40 -0700139 def __init__(self, name=None, **kwargs):
140 super().__init__(**kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +0000141 self.name = name
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700142
Gavin Makea2e3302023-03-11 06:46:20 +0000143 def __str__(self):
144 if self.name is None:
145 return "in current directory"
146 return self.name
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700147
Colin Cross5acde752012-03-28 20:15:45 -0700148
Jason Changa6413f52023-07-26 13:23:40 -0700149class InvalidProjectGroupsError(RepoExitError):
Gavin Makea2e3302023-03-11 06:46:20 +0000150 """A specified project is not suitable for the specified groups"""
David Pursehouse819827a2020-02-12 15:20:19 +0900151
Jason Changa6413f52023-07-26 13:23:40 -0700152 def __init__(self, name=None, **kwargs):
153 super().__init__(**kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +0000154 self.name = name
Colin Cross5acde752012-03-28 20:15:45 -0700155
Gavin Makea2e3302023-03-11 06:46:20 +0000156 def __str__(self):
157 if self.name is None:
158 return "in current directory"
159 return self.name
Colin Cross5acde752012-03-28 20:15:45 -0700160
David Pursehouse819827a2020-02-12 15:20:19 +0900161
Jason Changa6413f52023-07-26 13:23:40 -0700162class RepoChangedException(BaseRepoError):
Gavin Makea2e3302023-03-11 06:46:20 +0000163 """Thrown if 'repo sync' results in repo updating its internal
164 repo or manifest repositories. In this special case we must
165 use exec to re-execute repo with the new code and manifest.
166 """
David Pursehouse819827a2020-02-12 15:20:19 +0900167
Gavin Makea2e3302023-03-11 06:46:20 +0000168 def __init__(self, extra_args=None):
169 super().__init__(extra_args)
170 self.extra_args = extra_args or []
Doug Anderson37282b42011-03-04 11:54:18 -0800171
David Pursehouse819827a2020-02-12 15:20:19 +0900172
Jason Changa6413f52023-07-26 13:23:40 -0700173class HookError(RepoError):
Gavin Makea2e3302023-03-11 06:46:20 +0000174 """Thrown if a 'repo-hook' could not be run.
Doug Anderson37282b42011-03-04 11:54:18 -0800175
Gavin Makea2e3302023-03-11 06:46:20 +0000176 The common case is that the file wasn't present when we tried to run it.
177 """