blob: cee977f94c5f7b5f39565a2c4ede1de77c8e42e0 [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 <copyfile> or <linkfile> 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
Jason Changa6413f52023-07-26 13:23:40 -0700110class UploadError(RepoError):
Gavin Makea2e3302023-03-11 06:46:20 +0000111 """A bundle upload to Gerrit did not succeed."""
David Pursehouse819827a2020-02-12 15:20:19 +0900112
Jason Changa6413f52023-07-26 13:23:40 -0700113 def __init__(self, reason, **kwargs):
114 super().__init__(reason, **kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +0000115 self.reason = reason
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700116
Gavin Makea2e3302023-03-11 06:46:20 +0000117 def __str__(self):
118 return self.reason
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700119
David Pursehouse819827a2020-02-12 15:20:19 +0900120
Jason Changa6413f52023-07-26 13:23:40 -0700121class DownloadError(RepoExitError):
Gavin Makea2e3302023-03-11 06:46:20 +0000122 """Cannot download a repository."""
David Pursehouse819827a2020-02-12 15:20:19 +0900123
Jason Changa6413f52023-07-26 13:23:40 -0700124 def __init__(self, reason, **kwargs):
125 super().__init__(reason, **kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +0000126 self.reason = reason
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700127
Gavin Makea2e3302023-03-11 06:46:20 +0000128 def __str__(self):
129 return self.reason
Shawn O. Pearcef322b9a2011-09-19 14:50:58 -0700130
David Pursehouse819827a2020-02-12 15:20:19 +0900131
Jason Chang1a3612f2023-08-08 14:12:53 -0700132class InvalidArgumentsError(RepoExitError):
133 """Invalid command Arguments."""
134
135
Jason Changa6413f52023-07-26 13:23:40 -0700136class SyncError(RepoExitError):
137 """Cannot sync repo."""
138
139
140class UpdateManifestError(RepoExitError):
141 """Cannot update manifest."""
142
143
144class NoSuchProjectError(RepoExitError):
Gavin Makea2e3302023-03-11 06:46:20 +0000145 """A specified project does not exist in the work tree."""
David Pursehouse819827a2020-02-12 15:20:19 +0900146
Jason Changa6413f52023-07-26 13:23:40 -0700147 def __init__(self, name=None, **kwargs):
148 super().__init__(**kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +0000149 self.name = name
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700150
Gavin Makea2e3302023-03-11 06:46:20 +0000151 def __str__(self):
152 if self.name is None:
153 return "in current directory"
154 return self.name
The Android Open Source Projectcf31fe92008-10-21 07:00:00 -0700155
Colin Cross5acde752012-03-28 20:15:45 -0700156
Jason Changa6413f52023-07-26 13:23:40 -0700157class InvalidProjectGroupsError(RepoExitError):
Gavin Makea2e3302023-03-11 06:46:20 +0000158 """A specified project is not suitable for the specified groups"""
David Pursehouse819827a2020-02-12 15:20:19 +0900159
Jason Changa6413f52023-07-26 13:23:40 -0700160 def __init__(self, name=None, **kwargs):
161 super().__init__(**kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +0000162 self.name = name
Colin Cross5acde752012-03-28 20:15:45 -0700163
Gavin Makea2e3302023-03-11 06:46:20 +0000164 def __str__(self):
165 if self.name is None:
166 return "in current directory"
167 return self.name
Colin Cross5acde752012-03-28 20:15:45 -0700168
David Pursehouse819827a2020-02-12 15:20:19 +0900169
Jason Changa6413f52023-07-26 13:23:40 -0700170class RepoChangedException(BaseRepoError):
Gavin Makea2e3302023-03-11 06:46:20 +0000171 """Thrown if 'repo sync' results in repo updating its internal
172 repo or manifest repositories. In this special case we must
173 use exec to re-execute repo with the new code and manifest.
174 """
David Pursehouse819827a2020-02-12 15:20:19 +0900175
Gavin Makea2e3302023-03-11 06:46:20 +0000176 def __init__(self, extra_args=None):
177 super().__init__(extra_args)
178 self.extra_args = extra_args or []
Doug Anderson37282b42011-03-04 11:54:18 -0800179
David Pursehouse819827a2020-02-12 15:20:19 +0900180
Jason Changa6413f52023-07-26 13:23:40 -0700181class HookError(RepoError):
Gavin Makea2e3302023-03-11 06:46:20 +0000182 """Thrown if a 'repo-hook' could not be run.
Doug Anderson37282b42011-03-04 11:54:18 -0800183
Gavin Makea2e3302023-03-11 06:46:20 +0000184 The common case is that the file wasn't present when we tried to run it.
185 """