Skip to content

Commit

Permalink
Changes to raise exceptions for unsupported storage files (#2719)
Browse files Browse the repository at this point in the history
  • Loading branch information
Onager authored and joachimmetz committed Aug 20, 2019
1 parent f5f1a81 commit 9948c92
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
12 changes: 6 additions & 6 deletions plaso/cli/psort_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ def ProcessStorage(self):
"""Processes a plaso storage file.
Raises:
BadConfigOption: when a configuration parameter fails validation.
BadConfigOption: when a configuration parameter fails validation or the
storage file cannot be opened with read access.
RuntimeError: if a non-recoverable situation is encountered.
"""
self._CheckStorageFile(self._storage_file_path)
Expand All @@ -512,9 +513,9 @@ def ProcessStorage(self):
storage_reader = storage_factory.StorageFactory.CreateStorageReaderForFile(
self._storage_file_path)
if not storage_reader:
logger.error('Format of storage file: {0:s} not supported'.format(
self._storage_file_path))
return
raise errors.BadConfigOption(
'Format of storage file: {0:s} not supported'.format(
self._storage_file_path))

self._number_of_analysis_reports = (
storage_reader.GetNumberOfAnalysisReports())
Expand All @@ -532,10 +533,9 @@ def ProcessStorage(self):
storage_factory.StorageFactory.CreateStorageWriterForFile(
session, self._storage_file_path))
if not storage_writer:
logger.error(
raise errors.BadConfigOption(
'Format of storage file: {0:s} not supported for writing'.format(
self._storage_file_path))
return

# TODO: add single processing support.
analysis_engine = psort.PsortMultiProcessEngine()
Expand Down
9 changes: 5 additions & 4 deletions plaso/cli/psteal_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ def AnalyzeEvents(self):
"""Analyzes events from a plaso storage file and generate a report.
Raises:
BadConfigOption: when a configuration parameter fails validation.
BadConfigOption: when a configuration parameter fails validation or the
storage file cannot be opened with read access.
RuntimeError: if a non-recoverable situation is encountered.
"""
session = engine.BaseEngine.CreateSession(
Expand All @@ -186,9 +187,9 @@ def AnalyzeEvents(self):
storage_reader = storage_factory.StorageFactory.CreateStorageReaderForFile(
self._storage_file_path)
if not storage_reader:
logger.error('Format of storage file: {0:s} not supported'.format(
self._storage_file_path))
return
raise errors.BadConfigOption(
'Format of storage file: {0:s} not supported'.format(
self._storage_file_path))

self._number_of_analysis_reports = (
storage_reader.GetNumberOfAnalysisReports())
Expand Down
5 changes: 3 additions & 2 deletions tests/end-to-end.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ def _RunPsort(
command.extend(analysis_options)
command.extend(output_options)
command.extend(logging_options)
command.extend(['--status-view', 'none'])
command.extend(test_definition.profiling_options)

with open(stdout_file, 'w') as stdout:
Expand Down Expand Up @@ -1137,13 +1138,13 @@ def Run(self, test_definition):
output_options = ['--output-format', 'null']

if not self._RunPsort(
test_definition, temp_directory, source_path,
test_definition, temp_directory, storage_file,
analysis_options=analysis_options, output_options=output_options):
return False

# Check if the resulting storage file can be read with psort.
if not self._RunPsort(
test_definition, temp_directory, source_path,
test_definition, temp_directory, storage_file,
output_options=test_definition.output_options):
return False

Expand Down

0 comments on commit 9948c92

Please sign in to comment.