Debian Codegraph @

greenbone/feed/sync/errors.py

raw
1 # SPDX-FileCopyrightText: 2024 Greenbone AG
2 #
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18
19 from typing import Iterable, Optional
20
21
22 class GreenboneFeedSyncError(Exception):
23 """
24 Base exception class
25 """
26
27
28 class ConfigError(GreenboneFeedSyncError):
29 """
30 Error while processing a config
31 """
32
33
34 class ConfigFileError(ConfigError):
35 """
36 Error while processing a config file
37 """
38
39
40 class ExecProcessError(GreenboneFeedSyncError):
41 """
42 Error while executing a process
43 """
44
45 def __init__(
46 self,
47 returncode: int,
48 cmd: Iterable[str],
49 *,
50 stdout: Optional[bytes] = None,
51 stderr: Optional[bytes] = None,
52 ) -> None:
53 self.returncode = returncode
54 self.cmd = cmd
55 self.stout = (
56 None if not stdout else stdout.decode("utf8", errors="ignore")
57 )
58 self.stderr = (
59 None if not stderr else stderr.decode("utf8", errors="ignore")
60 )
61
62 def __str__(self):
63 cmd = " ".join(self.cmd)
64 return f"'{cmd}' returned non-zero exit status {self.returncode}."
65
66
67 class RsyncError(ExecProcessError):
68 """
69 Error while running rsync
70 """
71
72 def __init__(
73 self,
74 returncode: int,
75 args: Iterable[str],
76 stderr: Optional[bytes] = None,
77 ) -> None:
78 super().__init__(returncode, cmd=["rsync"] + list(args), stderr=stderr)
79
80
81 class FileLockingError(GreenboneFeedSyncError):
82 """
83 An error during locking a file
84 """