rembo10 / headphones

Automatic music downloader for SABnzbd
GNU General Public License v3.0
3.39k stars 600 forks source link

local variable 'result' referenced before assignment #3171

Closed torvitas closed 5 years ago

torvitas commented 5 years ago

Hi, one of the latest merged pull requests is causing a referenced before assignment error.

https://github.com/rembo10/headphones/pull/3160/files#diff-218eb437f645e77a753a988f6810cf6bR491

This is the commit: 81486d2cd2c61877f5b0a458dd6978f913b05eca

https://github.com/rembo10/headphones/blob/6208fe0e697825b49689b2f83e09d0b6d1144e98/headphones/searcher.py#L486-L493

500 Internal Server Error

The server encountered an unexpected condition which prevented it from fulfilling the request.

Traceback (most recent call last):
  File "/app/headphones/lib/cherrypy/_cprequest.py", line 670, in respond
    response.body = self.handler()
  File "/app/headphones/lib/cherrypy/lib/encoding.py", line 217, in __call__
    self.body = self.oldhandler(*args, **kwargs)
  File "/app/headphones/lib/cherrypy/_cpdispatch.py", line 61, in __call__
    return self.callable(*self.args, **self.kwargs)
  File "/app/headphones/headphones/webserve.py", line 435, in queueAlbum
    searcher.searchforalbum(AlbumID, new)
  File "/app/headphones/headphones/searcher.py", line 242, in searchforalbum
    do_sorted_search(album, new, losslessOnly)
  File "/app/headphones/headphones/searcher.py", line 334, in do_sorted_search
    sorted_search_results = sort_search_results(results, album, new, albumlength)
  File "/app/headphones/headphones/searcher.py", line 491, in sort_search_results
    if result[3] == 'Orpheus.network':
UnboundLocalError: local variable 'result' referenced before assignment
nopoz commented 5 years ago

I'm not seeing this error using the latest commit 6208fe0e697825b49689b2f83e09d0b6d1144e98

What are the steps to reproduce?

torvitas commented 5 years ago

I just realized that this is related to https://github.com/rembo10/headphones/issues/3172. If you add a trailing slash to the newznab url and click on search, new or want on an album the request results in the internal server error.

AdeHub commented 5 years ago

@doucheymcdoucherson can you have a look at https://github.com/rembo10/headphones/blob/master/headphones/searcher.py#L491 and https://github.com/rembo10/headphones/blob/master/headphones/searcher.py#L443, result[] is a list element and the list may not exist?

nopoz commented 5 years ago

result[3] is a list item for the provider which should always exist as far as I can tell?

I could change the reference of result[3] == to provider == in order to avoid referencing the list.

From @torvitas' description, this only occurs when there is a trailing slash on the newznab url? @torvitas can you confirm?

torvitas commented 5 years ago

I am not yet sure but the error seems to trigger on any empty result and a trailing slash on the newznab url leads to always empty results.

AdeHub commented 5 years ago

Silently failing for me and appears to be causing a few issues, have taken the code out for now