Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: KeyError: "u'version'"

### INFO
**Python Version**: `2.7.13 (default, Dec 18 2016, 21:23:50) [GCC 4.6.4]`
**Operating System**: `Linux-3.2.40-armv7l-with-glibc2.4`
**Locale**: `UTF-8`
**Branch**: [master](../tree/master)
**Database**: `44.8`
**Commit**: pymedusa/Medusa@7b9111eef5836a6846499ef257ffff3f1f35df8f
**Link to Log**: https://gist.github.com/adaeb1415fefd1083f59da7f01134ac6
### ERROR
<pre>
2017-12-29 19:52:25 ERROR    FINDPROPERS :: [7b9111e] BraceMessage string formatting failed. Using representation instead.
  File "/usr/local/python/lib/python2.7/threading.py", line 774, in __bootstrap
    self.__bootstrap_inner()
  File "/usr/local/python/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/volume1/@appstore/sickbeard-custom/var/<a href="../blob/7b9111eef5836a6846499ef257ffff3f1f35df8f/SickBeard/medusa/scheduler.py#L90">SickBeard/medusa/scheduler.py</a>", line 90, in run
    self.action.run(self.force)
  File "/volume1/@appstore/sickbeard-custom/var/<a href="../blob/7b9111eef5836a6846499ef257ffff3f1f35df8f/SickBeard/medusa/search/proper.py#L65">SickBeard/medusa/search/proper.py</a>", line 65, in run
    self._download_propers(propers)
  File "/volume1/@appstore/sickbeard-custom/var/<a href="../blob/7b9111eef5836a6846499ef257ffff3f1f35df8f/SickBeard/medusa/search/proper.py#L353">SickBeard/medusa/search/proper.py</a>", line 353, in _download_propers
    snatch_episode(cur_proper)
  File "/volume1/@appstore/sickbeard-custom/var/<a href="../blob/7b9111eef5836a6846499ef257ffff3f1f35df8f/SickBeard/medusa/search/core.py#L159">SickBeard/medusa/search/core.py</a>", line 159, in snatch_episode
    result_downloaded = client.send_torrent(result)
  File "/volume1/@appstore/sickbeard-custom/var/<a href="../blob/7b9111eef5836a6846499ef257ffff3f1f35df8f/SickBeard/medusa/clients/torrent/generic.py#L254">SickBeard/medusa/clients/torrent/generic.py</a>", line 254, in send_torrent
    r_code = self._add_torrent_uri(result)
  File "/volume1/@appstore/sickbeard-custom/var/<a href="../blob/7b9111eef5836a6846499ef257ffff3f1f35df8f/SickBeard/medusa/clients/torrent/download_station_client.py#L124">SickBeard/medusa/clients/torrent/download_station_client.py</a>", line 124, in _add_torrent_uri
    log.debug('Add torrent URI with data: {}'.format(data))
  File "/volume1/@appstore/sickbeard-custom/var/<a href="../blob/7b9111eef5836a6846499ef257ffff3f1f35df8f/SickBeard/medusa/logger/adapters/style.py#L89">SickBeard/medusa/logger/adapters/style.py</a>", line 89, in log
    self.logger.log(level, brace_msg, **kwargs)
  File "/usr/local/python/lib/python2.7/logging/__init__.py", line 1489, in log
    self.logger.log(level, msg, *args, **kwargs)
  File "/usr/local/python/lib/python2.7/logging/__init__.py", line 1231, in log
    self._log(level, msg, args, **kwargs)
  File "/usr/local/python/lib/python2.7/logging/__init__.py", line 1286, in _log
    self.handle(record)
  File "/usr/local/python/lib/python2.7/logging/__init__.py", line 1296, in handle
    self.callHandlers(record)
  File "/usr/local/python/lib/python2.7/logging/__init__.py", line 1336, in callHandlers
    hdlr.handle(record)
  File "/usr/local/python/lib/python2.7/logging/__init__.py", line 759, in handle
    self.emit(record)
  File "/usr/local/python/lib/python2.7/logging/handlers.py", line 78, in emit
    logging.FileHandler.emit(self, record)
  File "/usr/local/python/lib/python2.7/logging/__init__.py", line 957, in emit
    StreamHandler.emit(self, record)
  File "/usr/local/python/lib/python2.7/logging/__init__.py", line 861, in emit
    msg = self.format(record)
  File "/usr/local/python/lib/python2.7/logging/__init__.py", line 734, in format
    return fmt.format(record)
  File "/volume1/@appstore/sickbeard-custom/var/<a href="../blob/7b9111eef5836a6846499ef257ffff3f1f35df8f/SickBeard/medusa/logger/__init__.py#L546">SickBeard/medusa/logger/__init__.py</a>", line 546, in format
    msg = super(CensoredFormatter, self).format(record)
  File "/usr/local/python/lib/python2.7/logging/__init__.py", line 465, in format
    record.message = record.getMessage()
  File "/usr/local/python/lib/python2.7/logging/__init__.py", line 325, in getMessage
    msg = str(self.msg)
  File "/volume1/@appstore/sickbeard-custom/var/<a href="../blob/7b9111eef5836a6846499ef257ffff3f1f35df8f/SickBeard/medusa/init/logconfig.py#L80">SickBeard/medusa/init/logconfig.py</a>", line 80, in __str__
    result = text_type(self.fmt)
  File "/volume1/@appstore/sickbeard-custom/var/<a href="../blob/7b9111eef5836a6846499ef257ffff3f1f35df8f/SickBeard/medusa/logger/adapters/style.py#L49">SickBeard/medusa/logger/adapters/style.py</a>", line 49, in __str__
    ''.join(traceback.format_stack()),
Traceback (most recent call last):
  File "/volume1/@appstore/sickbeard-custom/var/<a href="../blob/7b9111eef5836a6846499ef257ffff3f1f35df8f/SickBeard/medusa/logger/adapters/style.py#L39">SickBeard/medusa/logger/adapters/style.py</a>", line 39, in __str__
    return msg.format(*args, **kwargs)
KeyError: "u'version'"
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators



Discussion:
Some additionnal info: this seems to happen whenever Medusa sends a torrent to download to Synology DS. 
It does work but this error message keeps popping in the logs.
I've played around with users permissions lately so I'm probably guilty (it worked fine a couple of days ago), however the error message is a bit harsh. :-)
Did you install Medusa using GitHub or downloading files from the repository?
@fernandog I updated it using GitHub after installing it through Synology Package Center.
@sephrat this has nothing to do with anything you did, it's due to a change in the logger to try to catch some errors that were slipping past unlogged.  A fix is in progress for this.
See #3531 

Resolving patch:
diff --git a/medusa/logger/adapters/style.py b/medusa/logger/adapters/style.py
--- a/medusa/logger/adapters/style.py
+++ b/medusa/logger/adapters/style.py
@@ -33,15 +33,15 @@ def __str__(self):
                 args = []
                 kwargs = self.args[0]
 
-        msg = text_type(self.msg)
-
         try:
-            return msg.format(*args, **kwargs)
+            return self.msg.format(*args, **kwargs)
         except IndexError:
             try:
-                return msg.format(kwargs)
-            except IndexError:
-                return msg
+                return self.msg.format(**kwargs)
+            except KeyError:
+                return self.msg
+        except KeyError:
+            return self.msg.format(*args)
         except Exception:
             log.error(
                 'BraceMessage string formatting failed. '
@@ -85,8 +85,9 @@ def log(self, level, msg, *args, **kwargs):
         """Log a message at the specified level using Brace-formatting."""
         if self.isEnabledFor(level):
             msg, kwargs = self.process(msg, kwargs)
-            brace_msg = BraceMessage(msg, *args, **kwargs)
-            self.logger.log(level, brace_msg, **kwargs)
+            if not isinstance(msg, BraceMessage):
+                msg = BraceMessage(msg, *args, **kwargs)
+            self.logger.log(level, msg, **kwargs)
 
     def exception(self, msg, *args, **kwargs):
         """Add exception information before delegating to self.log."""


Test patch: