-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexceptions.py
More file actions
101 lines (72 loc) · 3.17 KB
/
exceptions.py
File metadata and controls
101 lines (72 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#
# Sonar Scanner Python
# Copyright (C) 2011-2026 SonarSource Sàrl
# mailto:info AT sonarsource DOT com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
#
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
from dataclasses import dataclass
import logging
EXCEPTION_RETURN_CODE = 1
@dataclass
class MissingProperty:
property: str
cli_arg: str
class MissingPropertyException(Exception):
@staticmethod
def from_missing_keys(*properties: MissingProperty) -> "MissingPropertyException":
missing_properties = ", ".join([f"{prop.property} ({prop.cli_arg})" for prop in properties])
fix_message = (
"You can provide these properties using one of the following methods:\n"
"- Command line arguments (e.g., --sonar-project-key=myproject)\n"
"- Analysis parameters with -D prefix (e.g., -Dsonar.projectKey=myproject)\n"
"- Environment variables (e.g., SONAR_PROJECTKEY=myproject)\n"
"- Properties file (sonar-project.properties)\n"
"- Project configuration files (e.g., build.gradle, pom.xml)"
)
return MissingPropertyException(f"Missing required properties: {missing_properties}\n\n{fix_message}")
class SonarQubeApiException(Exception):
pass
class SonarQubeApiUnauthroizedException(SonarQubeApiException):
@staticmethod
def create_default(server_url: str) -> "SonarQubeApiUnauthroizedException":
return SonarQubeApiUnauthroizedException(
f'The provided token is invalid for the server at "{server_url}". Please check that both the token and the server URL are correct.'
)
class SQTooOldException(Exception):
pass
class InconsistentConfiguration(Exception):
pass
class ChecksumException(Exception):
@staticmethod
def create(what: str) -> "ChecksumException":
return ChecksumException(f"Checksum mismatch. The downloaded {what} is corrupted.")
class UnexpectedCliArgument(Exception):
pass
class JreProvisioningException(Exception):
pass
class NoJreAvailableException(JreProvisioningException):
pass
class UnsupportedArchiveFormat(JreProvisioningException):
pass
def log_error(e: Exception):
logger = logging.getLogger()
is_debug_level = logger.getEffectiveLevel() <= logging.DEBUG
if is_debug_level:
logger.error("The following exception occured while running the analysis", exc_info=True)
else:
logger.error(str(e), exc_info=False)
logger.info("For more details, please enable debug logging by passing the --verbose option.")
return EXCEPTION_RETURN_CODE