# Buggy code
def ExportEvents(
    self,
    knowledge_base_object,
    storage_reader,
    output_module,
    deduplicate_events=True,
    event_filter=None,
    status_update_callback=None,
    time_slice=None,
    use_time_slicer=False,
):
    """Exports events using an output module.

    Args:
      knowledge_base_object (KnowledgeBase): contains information from
          the source data needed for processing.
      storage_reader (StorageReader): storage reader.
      output_module (OutputModule): output module.
      deduplicate_events (Optional[bool]): True if events should be
          deduplicated.
      event_filter (Optional[FilterObject]): event filter.
      status_update_callback (Optional[function]): callback function for status
          updates.
      time_slice (Optional[TimeSlice]): slice of time to output.
      use_time_slicer (Optional[bool]): True if the 'time slicer' should be
          used. The 'time slicer' will provide a context of events around
          an event of interest.

    Returns:
      collections.Counter: counter that tracks the number of events extracted
          from storage.
    """
    self._status_update_callback = status_update_callback

    storage_reader.ReadPreprocessingInformation(knowledge_base_object)

    event_buffer = output_event_buffer.EventBuffer(output_module, deduplicate_events)

    with event_buffer:
        events_counter = self._ExportEvents(
            storage_reader,
            event_buffer,
            event_filter=event_filter,
            time_slice=time_slice,
            use_time_slicer=use_time_slicer,
        )

    # Reset values.
    self._status_update_callback = None

    return events_counter


# Traceback (KeyError)
[ERROR] (nsrlsvr   ) PID:XXXXX <analysis_process> <dfvfs.path.os_path_spec.OSPathSpec object at 0xXXXXXXXXXXXX>
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/plaso/multi_processing/analysis_process.py", line 138, in _Main
self._analysis_mediator.ProduceAnalysisReport(self._analysis_plugin)
File "/usr/lib/python2.7/dist-packages/plaso/analysis/mediator.py", line 95, in ProduceAnalysisReport
analysis_report = plugin.CompileReport(self)
File "/usr/lib/python2.7/dist-packages/plaso/analysis/interface.py", line 280, in CompileReport
hash_analysis)
File "/usr/lib/python2.7/dist-packages/plaso/analysis/interface.py", line 187, in _HandleHashAnalysis
event_uuids = self._event_uuids_by_pathspec.pop(pathspec)
KeyError: <dfvfs.path.os_path_spec.OSPathSpec object at 0xXXXXXXXXXXXX>

# Fixed code
def ExportEvents(
    self,
    knowledge_base_object,
    storage_reader,
    output_module,
    deduplicate_events=True,
    event_filter=None,
    status_update_callback=None,
    time_slice=None,
    use_time_slicer=False,
):
    """Exports events using an output module.

    Args:
      knowledge_base_object (KnowledgeBase): contains information from
          the source data needed for processing.
      storage_reader (StorageReader): storage reader.
      output_module (OutputModule): output module.
      deduplicate_events (Optional[bool]): True if events should be
          deduplicated.
      event_filter (Optional[FilterObject]): event filter.
      status_update_callback (Optional[function]): callback function for status
          updates.
      time_slice (Optional[TimeSlice]): slice of time to output.
      use_time_slicer (Optional[bool]): True if the 'time slicer' should be
          used. The 'time slicer' will provide a context of events around
          an event of interest.

    Returns:
      collections.Counter: counter that tracks the number of events extracted
          from storage.
    """
    self._status_update_callback = status_update_callback

    storage_reader.ReadPreprocessingInformation(knowledge_base_object)

    event_buffer = output_event_buffer.EventBuffer(output_module, deduplicate_events)

    self._StartStatusUpdateThread()

    try:
        with event_buffer:
            events_counter = self._ExportEvents(
                storage_reader,
                event_buffer,
                event_filter=event_filter,
                time_slice=time_slice,
                use_time_slicer=use_time_slicer,
            )

    finally:
        # Stop the status update thread after close of the storage writer
        # so we include the storage sync to disk in the status updates.
        self._StopStatusUpdateThread()

    # Reset values.
    self._status_update_callback = None

    return events_counter