mjishnu / pypdl

A concurrent pure python downloader with resume capablities
https://pypi.org/project/pypdl/
MIT License
44 stars 8 forks source link

Small logging enhancements (include traceback when logging exceptions, fix typos) #22

Closed Speyedr closed 1 month ago

Speyedr commented 1 month ago

Was tracking down a potential bug with multi-segment downloads and figured that when an error is logged while catching an exception, it should probably also log the traceback.

When an error occurred previously, only the following would be logged:

pypdl.log

(Pypdl)  21-07-24 15:10:51 - ERROR: (AttributeError) ['NoneType' object has no attribute 'get']

With this PR, instead the following would be logged:

pypdl.log

(Pypdl)  21-07-24 14:58:57 - ERROR: (AttributeError) ['NoneType' object has no attribute 'get']
Traceback (most recent call last):
  File "C:\Users\Speyedr\Documents\PyCharm Projects\pypdl-sticky-header-investigation\pypdl\pypdl_manager.py", line 103, in download
    result = self._execute(
             ^^^^^^^^^^^^^^
  File "C:\Users\Speyedr\Documents\PyCharm Projects\pypdl-sticky-header-investigation\pypdl\pypdl_manager.py", line 175, in _execute
    file_path, multisegment, etag = self._get_info(
                                    ^^^^^^^^^^^^^^^
  File "C:\Users\Speyedr\Documents\PyCharm Projects\pypdl-sticky-header-investigation\pypdl\pypdl_manager.py", line 230, in _get_info
    file_path = get_filepath(url, header, file_path)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Speyedr\Documents\PyCharm Projects\pypdl-sticky-header-investigation\pypdl\utls.py", line 32, in get_filepath
    content_disposition = headers.get("Content-Disposition", None)
                          ^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'get'

This is an easy change that can help identify errornous code quicker in the future.

I have also fixed some small grammar mistakes and typos in the logging messages themselves.