Skip to content

Commit 0b32c0d

Browse files
authored
CM-46370 - Add the error message from the server responses to the user space (#294)
1 parent 355d1c0 commit 0b32c0d

File tree

13 files changed

+32
-28
lines changed

13 files changed

+32
-28
lines changed

cycode/cli/apps/ignore/ignore_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ def ignore_command( # noqa: C901
5757
by_package: Annotated[
5858
Optional[str],
5959
typer.Option(
60-
help='Ignore scanning a specific package version. Expected pattern: [cyan]name@version[/cyan].',
60+
help='Ignore scanning a specific package version. Expected pattern: [cyan]name@version[/].',
6161
show_default=False,
6262
rich_help_panel=_SCA_FILTER_BY_RICH_HELP_PANEL,
6363
),
6464
] = None,
6565
by_cve: Annotated[
6666
Optional[str],
6767
typer.Option(
68-
help='Ignore scanning a specific CVE. Expected pattern: [cyan]CVE-YYYY-NNN[/cyan].',
68+
help='Ignore scanning a specific CVE. Expected pattern: [cyan]CVE-YYYY-NNN[/].',
6969
show_default=False,
7070
rich_help_panel=_SCA_FILTER_BY_RICH_HELP_PANEL,
7171
),

cycode/cli/apps/scan/code_scanner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def _get_default_scan_parameters(ctx: typer.Context) -> dict:
649649
'report': ctx.obj.get('report'),
650650
'package_vulnerabilities': ctx.obj.get('package-vulnerabilities'),
651651
'license_compliance': ctx.obj.get('license-compliance'),
652-
'command_type': ctx.info_name,
652+
'command_type': ctx.info_name.replace('-', '_'), # save backward compatibility
653653
'aggregation_id': str(_generate_unique_id()),
654654
}
655655

cycode/cli/apps/scan/scan_command.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ def scan_command(
8383
bool,
8484
typer.Option(
8585
'--no-restore',
86-
help='When specified, Cycode will not run restore command. '
87-
'Will scan direct dependencies [bold]only[/bold]!',
86+
help='When specified, Cycode will not run restore command. ' 'Will scan direct dependencies [b]only[/]!',
8887
rich_help_panel=_SCA_RICH_HELP_PANEL,
8988
),
9089
] = False,
@@ -93,14 +92,14 @@ def scan_command(
9392
typer.Option(
9493
'--gradle-all-sub-projects',
9594
help='When specified, Cycode will run gradle restore command for all sub projects. '
96-
'Should run from root project directory [bold]only[/bold]!',
95+
'Should run from root project directory [b]only[/]!',
9796
rich_help_panel=_SCA_RICH_HELP_PANEL,
9897
),
9998
] = False,
10099
) -> None:
101100
""":magnifying_glass_tilted_right: Scan the content for Secrets, IaC, SCA, and SAST violations.
102101
You'll need to specify which scan type to perform:
103-
[cyan]path[/cyan]/[cyan]repository[/cyan]/[cyan]commit_history[/cyan]."""
102+
[cyan]path[/]/[cyan]repository[/]/[cyan]commit_history[/]."""
104103
add_breadcrumb('scan')
105104

106105
ctx.obj['show_secret'] = show_secret

cycode/cli/apps/status/version_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66

77
def version_command(ctx: typer.Context) -> None:
8-
console.print('[yellow][bold]This command is deprecated. Please use the "status" command instead.[/bold][/yellow]')
8+
console.print('[b yellow]This command is deprecated. Please use the "status" command instead.[/]')
99
console.print() # print an empty line
1010
status_command(ctx)

cycode/cli/cli_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def get_member_color(name: str) -> str:
5757

5858
def __rich__(self) -> str:
5959
color = self.get_member_color(self.value)
60-
return f'[{color}]{self.value.upper()}[/{color}]'
60+
return f'[{color}]{self.value.upper()}[/]'
6161

6262

6363
_SEVERITY_DEFAULT_WEIGHT = -1

cycode/cli/exceptions/custom_exceptions.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
class CycodeError(Exception):
77
"""Base class for all custom exceptions"""
88

9+
def __str__(self) -> str:
10+
class_name = self.__class__.__name__
11+
return f'{class_name} error occurred.'
12+
913

1014
class RequestError(CycodeError): ...
1115

@@ -27,10 +31,7 @@ def __init__(self, status_code: int, error_message: str, response: Response) ->
2731
super().__init__(self.error_message)
2832

2933
def __str__(self) -> str:
30-
return (
31-
f'error occurred during the request. status code: {self.status_code}, error message: '
32-
f'{self.error_message}'
33-
)
34+
return f'HTTP error occurred during the request (code {self.status_code}). Message: {self.error_message}'
3435

3536

3637
class ScanAsyncError(CycodeError):
@@ -39,7 +40,7 @@ def __init__(self, error_message: str) -> None:
3940
super().__init__(self.error_message)
4041

4142
def __str__(self) -> str:
42-
return f'error occurred during the scan. error message: {self.error_message}'
43+
return f'Async scan error occurred during the scan. Message: {self.error_message}'
4344

4445

4546
class ReportAsyncError(CycodeError):
@@ -54,7 +55,7 @@ def __init__(self, error_message: str, response: Response) -> None:
5455
super().__init__(self.error_message)
5556

5657
def __str__(self) -> str:
57-
return 'Http Unauthorized Error'
58+
return f'HTTP unauthorized error occurred during the request. Message: {self.error_message}'
5859

5960

6061
class ZipTooLargeError(CycodeError):
@@ -72,7 +73,7 @@ def __init__(self, error_message: str) -> None:
7273
super().__init__()
7374

7475
def __str__(self) -> str:
75-
return f'Something went wrong during the authentication process, error message: {self.error_message}'
76+
return f'Something went wrong during the authentication process. Message: {self.error_message}'
7677

7778

7879
class TfplanKeyError(CycodeError):
@@ -106,6 +107,6 @@ def __str__(self) -> str:
106107
code='ssl_error',
107108
message='An SSL error occurred when trying to connect to the Cycode API. '
108109
'If you use an on-premises installation or a proxy that intercepts SSL traffic '
109-
'you should use the CURL_CA_BUNDLE environment variable to specify path to a valid .pem or similar.',
110+
'you should use the CURL_CA_BUNDLE environment variable to specify path to a valid .pem or similar',
110111
),
111112
}

cycode/cli/exceptions/handle_errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def handle_errors(
1414
ConsolePrinter(ctx).print_exception(err)
1515

1616
if type(err) in cli_errors:
17-
error = cli_errors[type(err)]
17+
error = cli_errors[type(err)].enrich(additional_message=str(err))
1818

1919
if error.soft_fail is True:
2020
ctx.obj['soft_fail'] = True

cycode/cli/models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class CliError(NamedTuple):
3737
message: str
3838
soft_fail: bool = False
3939

40+
def enrich(self, additional_message: str) -> 'CliError':
41+
message = f'{self.message} ({additional_message})'
42+
return CliError(self.code, message, self.soft_fail)
43+
4044

4145
CliErrors = Dict[Type[BaseException], CliError]
4246

cycode/cli/printers/printer_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
class PrinterBase(ABC):
1919
NO_DETECTIONS_MESSAGE = (
20-
'[green]Good job! No issues were found!!! :clapping_hands::clapping_hands::clapping_hands:[/green]'
20+
'[green]Good job! No issues were found!!! :clapping_hands::clapping_hands::clapping_hands:[/]'
2121
)
2222
FAILED_SCAN_MESSAGE = (
2323
'[red]Unfortunately, Cycode was unable to complete the full scan. '
24-
'Please note that not all results may be available:[/red]'
24+
'Please note that not all results may be available:[/]'
2525
)
2626

2727
def __init__(self, ctx: typer.Context) -> None:
@@ -56,4 +56,4 @@ def print_exception(e: Optional[BaseException] = None) -> None:
5656
rich_traceback.show_locals = False
5757
console_err.print(rich_traceback)
5858

59-
console_err.print(f'[red]Correlation ID:[/red] {get_correlation_id()}')
59+
console_err.print(f'[red]Correlation ID:[/] {get_correlation_id()}')

cycode/cli/printers/tables/sca_table_printer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def _enrich_table_with_values(policy_id: str, table: Table, detection: Detection
178178

179179
@staticmethod
180180
def _print_summary_issues(detections_count: int, title: str) -> None:
181-
console.print(f':no_entry: Found {detections_count} issues of type: [bold]{title}[/bold]')
181+
console.print(f':no_entry: Found {detections_count} issues of type: [b]{title}[/]')
182182

183183
@staticmethod
184184
def _extract_detections_per_policy_id(

0 commit comments

Comments
 (0)