Debian Codegraph @

src/briefcase/exceptions.py

raw
1 class BriefcaseError(Exception):
2 def __init__(self, error_code, skip_logfile=False):
3 self.error_code = error_code
4 self.skip_logfile = skip_logfile
5
6
7 class BriefcaseWarning(Exception):
8 def __init__(self, error_code, msg):
9 self.error_code = error_code
10 self.msg = msg
11
12 def __str__(self):
13 return self.msg
14
15
16 class HelpText(BriefcaseError):
17 """Exceptions that contain help text and shouldn't be displayed as an error."""
18
19
20 class InputDisabled(BriefcaseError):
21 def __init__(
22 self,
23 msg="Input is disabled; cannot request user input without a default",
24 ):
25 super().__init__(error_code=99)
26 self.msg = msg
27
28 def __str__(self):
29 return self.msg
30
31
32 class NoCommandError(HelpText):
33 def __init__(self, msg):
34 super().__init__(error_code=-10, skip_logfile=True)
35 self.msg = msg
36
37 def __str__(self):
38 return self.msg
39
40
41 class InvalidPlatformError(BriefcaseError):
42 def __init__(self, requested, choices):
43 super().__init__(error_code=-20, skip_logfile=True)
44 self.requested = requested
45 self.choices = choices
46
47 def __str__(self):
48 choices = ", ".join(sorted(self.choices, key=str.lower))
49 return f"Invalid platform {self.requested!r}; (choose from: {choices})"
50
51
52 class InvalidFormatError(BriefcaseError):
53 def __init__(self, requested, choices):
54 super().__init__(error_code=-21, skip_logfile=True)
55 self.requested = requested
56 self.choices = choices
57
58 def __str__(self):
59 choices = ", ".join(sorted(self.choices, key=str.lower))
60 return f"Invalid format {self.requested!r}; (choose from: {choices})"
61
62
63 class UnsupportedCommandError(BriefcaseError):
64 def __init__(self, platform, output_format, command):
65 super().__init__(error_code=-30, skip_logfile=True)
66 self.platform = platform
67 self.output_format = output_format
68 self.command = command
69
70 def __str__(self):
71 return (
72 f"The {self.command} command for the {self.platform} {self.output_format} "
73 f"format has not been implemented (yet!)."
74 )
75
76
77 class BriefcaseConfigError(BriefcaseError):
78 def __init__(self, msg):
79 super().__init__(error_code=100, skip_logfile=True)
80 self.msg = msg
81
82 def __str__(self):
83 return f"Briefcase configuration error: {self.msg}"
84
85
86 class InvalidVersionError(BriefcaseConfigError):
87 def __init__(self, msg):
88 super().__init__(
89 f"{msg}\n\n"
90 "Version numbers must be PEP440 compliant; see "
91 "https://packaging.python.org/en/latest/specifications/version-specifiers/"
92 " for details."
93 )
94
95
96 class UnsupportedHostError(BriefcaseError):
97 def __init__(self, reason):
98 super().__init__(error_code=110, skip_logfile=True)
99 self.msg = reason
100
101 def __str__(self):
102 return self.msg
103
104
105 class BriefcaseCommandError(BriefcaseError):
106 def __init__(self, msg, skip_logfile=False):
107 super().__init__(error_code=200, skip_logfile=skip_logfile)
108 self.msg = msg
109
110 def __str__(self):
111 return self.msg
112
113
114 class NetworkFailure(BriefcaseCommandError):
115 DEFAULT_HINT = "is your computer offline?"
116
117 def __init__(self, action, hint=None):
118 self.action = action
119 self.hint = hint or self.DEFAULT_HINT
120 super().__init__(msg=f"Unable to {action}; {self.hint}")
121
122
123 class MissingNetworkResourceError(BriefcaseCommandError):
124 def __init__(self, url):
125 self.url = url
126 super().__init__(msg=f"Unable to download {url}; is the URL correct?")
127
128
129 class BadNetworkResourceError(BriefcaseCommandError):
130 def __init__(self, url, status_code):
131 self.url = url
132 self.status_code = status_code
133 super().__init__(msg=f"Unable to download {url} (status code {status_code})")
134
135
136 class MissingToolError(BriefcaseCommandError):
137 def __init__(self, tool):
138 self.tool = tool
139 super().__init__(msg=f"Unable to locate {tool!r}. Has it been installed?")
140
141
142 class IncompatibleToolError(BriefcaseCommandError):
143 def __init__(self, tool: str, env_var: str):
144 self.tool = tool
145 super().__init__(
146 msg=(
147 f"Briefcase cannot install {tool} on this machine."
148 f"\n\n"
149 f"Install {tool} manually and specify the installation "
150 f"directory in the {env_var} environment variable."
151 )
152 )
153
154
155 class NonManagedToolError(BriefcaseCommandError):
156 def __init__(self, tool):
157 self.tool = tool
158 super().__init__(msg=f"{tool!r} is using an install that is user managed.")
159
160
161 class UpgradeToolError(BriefcaseCommandError):
162 def __init__(self, error_msg):
163 super().__init__(msg=error_msg, skip_logfile=True)
164
165
166 class InvalidTemplateBranch(BriefcaseCommandError):
167 def __init__(self, template_repo, branch):
168 self.template_repo = template_repo
169 self.branch = branch
170 super().__init__(
171 f"Could not find a branch named {branch!r} "
172 f"in template repository {template_repo!r}."
173 )
174
175
176 class InvalidTemplateRepository(BriefcaseCommandError):
177 def __init__(self, template):
178 self.template = template
179 super().__init__(
180 f"Unable to clone application template; "
181 f"is the template path {template!r} correct?"
182 )
183
184
185 class UnsupportedPlatform(BriefcaseCommandError):
186 def __init__(self, platform):
187 self.platform = platform
188 super().__init__(
189 f"""\
190 App cannot be deployed on {platform}. This is probably because one or more
191 requirements (e.g., the GUI library) doesn't support {platform}.
192 """
193 )
194
195
196 class InvalidSupportPackage(BriefcaseCommandError):
197 def __init__(self, filename):
198 self.filename = filename
199 super().__init__(f"Unable to unpack support package {str(filename)!r}.")
200
201
202 class InvalidStubBinary(BriefcaseCommandError):
203 def __init__(self, filename):
204 self.filename = filename
205 super().__init__(f"Unable to unpack or copy stub binary {str(filename)!r}.")
206
207
208 class MissingAppMetadata(BriefcaseCommandError):
209 def __init__(self, app_bundle_path):
210 super().__init__(f"Unable to find {str(app_bundle_path / 'briefcase.toml')!r}")
211
212
213 class MissingPlatformSupport(BriefcaseCommandError):
214 def __init__(self, python_version_tag, platform, host_arch, is_32bit, item):
215 self.python_version_tag = python_version_tag
216 self.platform = platform
217 self.host_arch = host_arch
218 self.is_32bit = is_32bit
219 platform_name = f"{'32 bit ' if is_32bit else ''}{platform}"
220 super().__init__(
221 f"Unable to download {platform_name} {item} for Python "
222 f"{python_version_tag} on {host_arch}."
223 f"\n\n"
224 f"This is likely because either Python {python_version_tag} and/or "
225 f"{host_arch} is not yet supported on {platform_name}."
226 f"\n\n"
227 f"You will need to:\n"
228 f"* Use an older version of Python; or\n"
229 f"* Compile your own {item}."
230 )
231
232
233 class MissingSupportPackage(MissingPlatformSupport):
234 def __init__(self, python_version_tag, platform, host_arch, is_32bit):
235 super().__init__(
236 python_version_tag, platform, host_arch, is_32bit, "support package"
237 )
238
239
240 class MissingStubBinary(MissingPlatformSupport):
241 def __init__(self, python_version_tag, platform, host_arch, is_32bit):
242 super().__init__(
243 python_version_tag, platform, host_arch, is_32bit, "stub binary"
244 )
245
246
247 class RequirementsInstallError(BriefcaseCommandError):
248 def __init__(self, install_hint=""):
249 super().__init__(
250 f"""\
251 Unable to install requirements. This may be because one of your
252 requirements is invalid, or because pip was unable to connect
253 to the PyPI server.{install_hint}
254 """
255 )
256
257
258 class UnsupportedPythonVersion(BriefcaseCommandError):
259 def __init__(self, version_specifier, running_version):
260 super().__init__(
261 f"""\
262 Unable to run Briefcase command. The project configuration requires
263 Python versions {version_specifier}, but the environment's Python
264 version is {running_version}. Please run Briefcase using a Python
265 version that satisfies the project's requirements.
266 """
267 )
268
269
270 class MissingAppSources(BriefcaseCommandError):
271 def __init__(self, src):
272 self.src = src
273 super().__init__(f"Application source {src!r} does not exist.")
274
275
276 class InvalidDeviceError(BriefcaseCommandError):
277 def __init__(self, id_type, device):
278 self.id_type = id_type
279 self.device = device
280 super().__init__(msg=f"Invalid device {id_type} {device!r}")
281
282
283 class CorruptToolError(BriefcaseCommandError):
284 def __init__(self, tool):
285 self.tool = tool
286 super().__init__(msg=f"{tool!r} found, but it appears to be corrupted.")
287
288
289 class CommandOutputParseError(BriefcaseCommandError):
290 def __init__(self, parse_error):
291 super().__init__(msg=f"Unable to parse command output: {parse_error}")
292
293
294 class BriefcaseTestSuiteFailure(BriefcaseError):
295 def __init__(self):
296 super().__init__(error_code=1000, skip_logfile=True)
297
298
299 class NoDistributionArtefact(BriefcaseWarning):
300 def __init__(self, msg):
301 super().__init__(error_code=0, msg=msg)
302
303
304 class NotarizationInterrupted(BriefcaseWarning):
305 def __init__(self, msg):
306 super().__init__(error_code=0, msg=msg)
307
308
309 class ParseError(Exception):
310 """Raised by parser functions to signal parsing was unsuccessful."""