Skip to content

Commit

Permalink
Refactor error handling and logging in '''get_extractor''' - main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronatp authored Nov 13, 2023
1 parent 74f7085 commit 0861e8a
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions capa/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ def get_workspace(path: Path, format_: str, sigpaths: List[Path]):
return vw


@catch_log_return_errors
def get_extractor(
path: Path,
format_: str,
Expand Down Expand Up @@ -1257,25 +1258,16 @@ def main(argv: Optional[List[str]] = None):

should_save_workspace = os.environ.get("CAPA_SAVE_WORKSPACE") not in ("0", "no", "NO", "n", None)

try:
extractor = get_extractor(
args.sample,
format_,
args.os,
args.backend,
sig_paths,
should_save_workspace,
disable_progress=args.quiet or args.debug,
)
except UnsupportedFormatError:
log_unsupported_format_error()
return E_INVALID_FILE_TYPE
except UnsupportedArchError:
log_unsupported_arch_error()
return E_INVALID_FILE_ARCH
except UnsupportedOSError:
log_unsupported_os_error()
return E_INVALID_FILE_OS
# Error checking and logging is performed in the get_extractor call
extractor = get_extractor(
args.sample,
format_,
args.os,
args.backend,
sig_paths,
should_save_workspace,
disable_progress=args.quiet or args.debug,
)

meta = collect_metadata(argv, args.sample, args.format, args.os, args.rules, extractor)

Expand Down

0 comments on commit 0861e8a

Please sign in to comment.