blob: fb48e866e6bf1bb18f7c5b03a59b822bd226c56b [file] [log] [blame]
Justin Luong97eda6f2022-08-23 01:29:16 +00001# Copyright 2022 The LUCI Authors. All rights reserved.
2# Use of this source code is governed under the Apache License, Version 2.0
3# that can be found in the LICENSE file.
4"""Exceptions for handling CIPD and CAS errors"""
5
6
7class NonRecoverableException(Exception):
8 """For handling errors where we cannot recover from and should not retry."""
9
10 def __init__(self, status, msg):
11 super(Exception, self).__init__(msg)
12 self.status = status
13
14 def to_dict(self):
15 """Returns a dictionary with the attributes serialised."""
16 raise NotImplementedError()
17
18
19class NonRecoverableCasException(NonRecoverableException):
20 """For handling a bad CAS input where we should not attempt to retry."""
21
22 def __init__(self, status, digest, instance):
23 super(NonRecoverableCasException, self).__init__(
24 status, "CAS error: {} with digest {} on instance {}".format(
25 status, digest, instance))
26 self.digest = digest
27 self.instance = instance
28
29 def to_dict(self):
30 return {
31 'status': self.status,
32 'digest': self.digest,
33 'instance': self.instance,
34 }
35
36
37class NonRecoverableCipdException(NonRecoverableException):
38 """For handling a bad CIPD package where we should not attempt to retry."""
39
40 def __init__(self, status, package_name, path, version):
41 super(NonRecoverableCipdException, self).__init__(
42 status, "CIPD error: {} with package {}, version {} on path {}".format(
43 status, package_name, version, path))
44 self.package_name = package_name
45 self.path = path
46 self.version = version
47
48 def to_dict(self):
49 return {
50 'status': self.status,
51 'package_name': self.package_name,
52 'path': self.path,
53 'version': self.version
54 }