Commit b0033e5fd67b922187053af296e53f2899b46cc9

Authored by Christian Herdtweck
1 parent 40c14afb

do not log error if in json mode -- error info is in json-output and return code

Showing 1 changed file with 10 additions and 9 deletions
oletools/olevba.py
@@ -2970,14 +2970,14 @@ def main(): @@ -2970,14 +2970,14 @@ def main():
2970 if isinstance(data, PathNotFoundException): 2970 if isinstance(data, PathNotFoundException):
2971 if options.output_mode in ('triage', 'unspecified'): 2971 if options.output_mode in ('triage', 'unspecified'):
2972 print '%-12s %s - File not found' % ('?', filename) 2972 print '%-12s %s - File not found' % ('?', filename)
2973 - else: 2973 + elif options.output_mode != 'json':
2974 log.error('Given path %r does not exist!' % filename) 2974 log.error('Given path %r does not exist!' % filename)
2975 return_code = RETURN_FILE_NOT_FOUND if return_code == 0 \ 2975 return_code = RETURN_FILE_NOT_FOUND if return_code == 0 \
2976 else RETURN_SEVERAL_ERRS 2976 else RETURN_SEVERAL_ERRS
2977 else: 2977 else:
2978 if options.output_mode in ('triage', 'unspecified'): 2978 if options.output_mode in ('triage', 'unspecified'):
2979 print '%-12s %s - Failed to read from zip file %s' % ('?', filename, container) 2979 print '%-12s %s - Failed to read from zip file %s' % ('?', filename, container)
2980 - else: 2980 + elif options.output_mode != 'json':
2981 log.error('Exception opening/reading %r from zip file %r: %s' 2981 log.error('Exception opening/reading %r from zip file %r: %s'
2982 % (filename, container, data)) 2982 % (filename, container, data))
2983 return_code = RETURN_XGLOB_ERR if return_code == 0 \ 2983 return_code = RETURN_XGLOB_ERR if return_code == 0 \
@@ -3020,23 +3020,23 @@ def main(): @@ -3020,23 +3020,23 @@ def main():
3020 except FileOpenError as exc: 3020 except FileOpenError as exc:
3021 if options.output_mode in ('triage', 'unspecified'): 3021 if options.output_mode in ('triage', 'unspecified'):
3022 print '%-12s %s - File format not supported' % ('?', filename) 3022 print '%-12s %s - File format not supported' % ('?', filename)
3023 - else:  
3024 - log.exception('Failed to open %s -- probably not supported!' % filename)  
3025 - if options.output_mode == 'json': 3023 + elif options.output_mode == 'json':
3026 print_json(file=filename, type='error', 3024 print_json(file=filename, type='error',
3027 error=type(exc).__name__, message=str(exc)) 3025 error=type(exc).__name__, message=str(exc))
  3026 + else:
  3027 + log.exception('Failed to open %s -- probably not supported!' % filename)
3028 return_code = RETURN_OPEN_ERROR if return_code == 0 \ 3028 return_code = RETURN_OPEN_ERROR if return_code == 0 \
3029 else RETURN_SEVERAL_ERRS 3029 else RETURN_SEVERAL_ERRS
3030 except ProcessingError as exc: 3030 except ProcessingError as exc:
3031 if options.output_mode in ('triage', 'unspecified'): 3031 if options.output_mode in ('triage', 'unspecified'):
3032 print '%-12s %s - %s' % ('!ERROR', filename, exc.orig_exception) 3032 print '%-12s %s - %s' % ('!ERROR', filename, exc.orig_exception)
3033 - else:  
3034 - log.exception('Error processing file %s (%s)!'  
3035 - % (filename, exc.orig_exception))  
3036 - if options.output_mode == 'json': 3033 + elif options.output_mode == 'json':
3037 print_json(file=filename, type='error', 3034 print_json(file=filename, type='error',
3038 error=type(exc).__name__, 3035 error=type(exc).__name__,
3039 message=str(exc.orig_exception)) 3036 message=str(exc.orig_exception))
  3037 + else:
  3038 + log.exception('Error processing file %s (%s)!'
  3039 + % (filename, exc.orig_exception))
3040 return_code = RETURN_PARSE_ERROR if return_code == 0 \ 3040 return_code = RETURN_PARSE_ERROR if return_code == 0 \
3041 else RETURN_SEVERAL_ERRS 3041 else RETURN_SEVERAL_ERRS
3042 finally: 3042 finally:
@@ -3064,6 +3064,7 @@ def main(): @@ -3064,6 +3064,7 @@ def main():
3064 except Exception as exc: 3064 except Exception as exc:
3065 # some unexpected error, maybe some of the types caught in except clauses 3065 # some unexpected error, maybe some of the types caught in except clauses
3066 # above were not sufficient. This is very bad, so log complete trace at exception level 3066 # above were not sufficient. This is very bad, so log complete trace at exception level
  3067 + # and do not care about output mode
3067 log.exception('Unhandled exception in main: %s' % exc, exc_info=True) 3068 log.exception('Unhandled exception in main: %s' % exc, exc_info=True)
3068 return_code = RETURN_UNEXPECTED # even if there were others before -- this is more important 3069 return_code = RETURN_UNEXPECTED # even if there were others before -- this is more important
3069 3070