-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathhandle_scan_errors.py
More file actions
51 lines (45 loc) · 2.14 KB
/
handle_scan_errors.py
File metadata and controls
51 lines (45 loc) · 2.14 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
from typing import Optional
import typer
from cycode.cli.exceptions import custom_exceptions
from cycode.cli.exceptions.custom_exceptions import KNOWN_USER_FRIENDLY_REQUEST_ERRORS
from cycode.cli.exceptions.handle_errors import handle_errors
from cycode.cli.models import CliError, CliErrors
from cycode.cli.utils.git_proxy import git_proxy
def handle_scan_exception(ctx: typer.Context, err: Exception, *, return_exception: bool = False) -> Optional[CliError]:
ctx.obj['did_fail'] = True
errors: CliErrors = {
**KNOWN_USER_FRIENDLY_REQUEST_ERRORS,
custom_exceptions.ScanAsyncError: CliError(
soft_fail=True,
code='scan_error',
message='Cycode was unable to complete this scan. Please try again by executing the `cycode scan` command',
),
custom_exceptions.ZipTooLargeError: CliError(
soft_fail=True,
code='zip_too_large_error',
message='The path you attempted to scan exceeds the current maximum scanning size cap (10MB). '
'Please try ignoring irrelevant paths using the `cycode ignore --by-path` command '
'and execute the scan again',
),
custom_exceptions.FileCollectionError: CliError(
soft_fail=False,
code='file_collection_error',
message='File collection failed. '
'Use --no-restore to skip dependency restoration, or fix the underlying issue.',
),
custom_exceptions.TfplanKeyError: CliError(
soft_fail=True,
code='key_error',
message=f'\n{err!s}\n'
'A crucial field is missing in your terraform plan file. '
'Please make sure that your file is well formed '
'and execute the scan again',
),
git_proxy.get_invalid_git_repository_error(): CliError(
soft_fail=False,
code='invalid_git_error',
message='The path you supplied does not correlate to a Git repository. '
'If you still wish to scan this path, use: `cycode scan path <path>`',
),
}
return handle_errors(ctx, err, errors, return_exception=return_exception)