# Buggy code
def handle(err, message="", *args, **kwargs):
    """Single entry point to handle unhandled exceptions.

    :param err:
    :param message:
    :type err: Exception
    """
    m = message.format(*args, **kwargs) + ": " if message else ""
    if isinstance(err, OSError):
        if err.errno == 28:
            logger.warning("{m}Out of disk space: {error_msg}", m=m, error_msg=err)
        elif err.errno == 13:
            logger.warning("{m}Permission denied: {error_msg}", m=m, error_msg=err)
        else:
            logger.warning("{m}OS error: {error_msg}", m=m, error_msg=err)
    else:
        logger.exception("{m}Exception generated: {error_msg}", m=m, error_msg=err)


# Traceback (IOError)
2016-11-02 15:10:15 DEBUG    POSTPROCESSOR :: [1fdd694] Using scores {'hash': 359, 'format': 7, 'series': 180, 'audio_codec': 3, 'year': 90, 'hearing_impaired': 1, 'episode': 30, 'season': 30, 'video_codec': 2, 'resolution': 2, 'release_group': 15}
2016-11-02 15:10:17 DEBUG    POSTPROCESSOR :: [1fdd694] Found matches set(['episode', 'season', 'year', 'video_codec'])
2016-11-02 15:10:17 DEBUG    POSTPROCESSOR :: [1fdd694] Matched hearing_impaired
2016-11-02 15:10:17 DEBUG    POSTPROCESSOR :: [1fdd694] Computed score 153 with final matches set(['episode', 'season', 'year', 'video_codec', 'hearing_impaired'])
2016-11-02 15:10:17 DEBUG    POSTPROCESSOR :: [1fdd694] Computing score of <OpenSubtitlesSubtitle '1955254294' [pt-BR]> for video <Episode ['Cordon', 2014, 1x10]> with {'hearing_impaired': False}
2016-11-02 15:10:17 DEBUG    POSTPROCESSOR :: [1fdd694] Using scores {'hash': 359, 'format': 7, 'series': 180, 'audio_codec': 3, 'year': 90, 'hearing_impaired': 1, 'episode': 30, 'season': 30, 'video_codec': 2, 'resolution': 2, 'release_group': 15}
2016-11-02 15:10:19 DEBUG    SEARCHQUEUE-MANUAL-296069 :: [Zooqle] :: [1fdd694] Data returned from provider does not contain any torrents
2016-11-02 15:10:19 DEBUG    SEARCHQUEUE-MANUAL-296069 :: [Zooqle] :: [1fdd694] Search string: Paul and Nicks Big American Food Trip S01
2016-11-02 15:10:19 DEBUG    POSTPROCESSOR :: [1fdd694] Found matches set(['episode', 'year', 'season', 'video_codec'])
2016-11-02 15:10:19 DEBUG    POSTPROCESSOR :: [1fdd694] Matched hearing_impaired
2016-11-02 15:10:19 DEBUG    POSTPROCESSOR :: [1fdd694] Computed score 153 with final matches set(['episode', 'year', 'season', 'video_codec', 'hearing_impaired'])
2016-11-02 15:10:19 DEBUG    POSTPROCESSOR :: [1fdd694] [opensubtitles:en   ] score = 153/352 for Containment.S01E10.HDTV.x264-LOL.srt
2016-11-02 15:10:19 DEBUG    POSTPROCESSOR :: [1fdd694] [opensubtitles:pt-BR] score = 153/352 for Containment.S01E10.1080p.HDTV.X264-DIMENSION.srt
2016-11-02 15:10:19 DEBUG    POSTPROCESSOR :: [1fdd694] [opensubtitles:pt-BR] score = 153/352 for Containment.S01E10.1080p.WEB-DL.DD5.1.H264-RARBG.srt
2016-11-02 15:10:19 DEBUG    POSTPROCESSOR :: [1fdd694] [opensubtitles:en   ] score = 152/352 for Containment.S01E10.HDTV.x264-LOL.srt
2016-11-02 15:10:19 DEBUG    POSTPROCESSOR :: [1fdd694] [opensubtitles:en   ] score = 152/352 for Containment.S01E10.HDTV.x264-LOL.srt
2016-11-02 15:10:19 DEBUG    POSTPROCESSOR :: [1fdd694] Computing score of <OpenSubtitlesSubtitle '1955249500' [en]> for video <Episode ['Cordon', 2014, 1x10]> with {'hearing_impaired': False}
2016-11-02 15:10:19 DEBUG    POSTPROCESSOR :: [1fdd694] Using scores {'hash': 359, 'format': 7, 'series': 180, 'audio_codec': 3, 'year': 90, 'hearing_impaired': 1, 'episode': 30, 'season': 30, 'video_codec': 2, 'resolution': 2, 'release_group': 15}
2016-11-02 15:10:19 DEBUG    SEARCHQUEUE-MANUAL-296069 :: [Zooqle] :: [1fdd694] GET URL: https://zooqle.com/search?q=Paul+and+Nicks+Big+American+Food+Trip+S01+category%3ATV [Status: 200]
2016-11-02 15:10:20 DEBUG    POSTPROCESSOR :: [1fdd694] Found matches set(['episode', 'video_codec', 'season', 'year'])
2016-11-02 15:10:20 DEBUG    POSTPROCESSOR :: [1fdd694] Computed score 152 with final matches set(['episode', 'video_codec', 'season', 'year'])
2016-11-02 15:10:20 DEBUG    POSTPROCESSOR :: [1fdd694] Computing score of <OpenSubtitlesSubtitle '1955249501' [en]> for video <Episode ['Cordon', 2014, 1x10]> with {'hearing_impaired': False}
2016-11-02 15:10:20 DEBUG    POSTPROCESSOR :: [1fdd694] Using scores {'hash': 359, 'format': 7, 'series': 180, 'audio_codec': 3, 'year': 90, 'hearing_impaired': 1, 'episode': 30, 'season': 30, 'video_codec': 2, 'resolution': 2, 'release_group': 15}
2016-11-02 15:10:21 DEBUG    POSTPROCESSOR :: [1fdd694] Found matches set(['episode', 'video_codec', 'season', 'year'])
2016-11-02 15:10:21 DEBUG    POSTPROCESSOR :: [1fdd694] Matched hearing_impaired
2016-11-02 15:10:21 DEBUG    POSTPROCESSOR :: [1fdd694] Computed score 153 with final matches set(['episode', 'video_codec', 'season', 'year', 'hearing_impaired'])
2016-11-02 15:10:21 DEBUG    POSTPROCESSOR :: [1fdd694] Computing score of <OpenSubtitlesSubtitle '1955250232' [en]> for video <Episode ['Cordon', 2014, 1x10]> with {'hearing_impaired': False}
2016-11-02 15:10:21 DEBUG    POSTPROCESSOR :: [1fdd694] Using scores {'hash': 359, 'format': 7, 'series': 180, 'audio_codec': 3, 'year': 90, 'hearing_impaired': 1, 'episode': 30, 'season': 30, 'video_codec': 2, 'resolution': 2, 'release_group': 15}
2016-11-02 15:10:24 DEBUG    POSTPROCESSOR :: [1fdd694] Found matches set(['episode', 'video_codec', 'season', 'year'])
2016-11-02 15:10:24 DEBUG    POSTPROCESSOR :: [1fdd694] Computed score 152 with final matches set(['episode', 'video_codec', 'season', 'year'])
2016-11-02 15:10:24 DEBUG    POSTPROCESSOR :: [1fdd694] Computing score of <OpenSubtitlesSubtitle '1955252227' [pt-BR]> for video <Episode ['Cordon', 2014, 1x10]> with {'hearing_impaired': False}
2016-11-02 15:10:24 DEBUG    POSTPROCESSOR :: [1fdd694] Using scores {'hash': 359, 'format': 7, 'series': 180, 'audio_codec': 3, 'year': 90, 'hearing_impaired': 1, 'episode': 30, 'season': 30, 'video_codec': 2, 'resolution': 2, 'release_group': 15}
2016-11-02 15:10:25 DEBUG    SEARCHQUEUE-MANUAL-296069 :: [Zooqle] :: [1fdd694] Data returned from provider does not contain any torrents
2016-11-02 15:10:25 INFO     SEARCHQUEUE-MANUAL-296069 :: [ThePirateBay] :: [1fdd694] Performing season pack search for Paul and Nick’s Big American Food Trip
2016-11-02 15:10:25 DEBUG    SEARCHQUEUE-MANUAL-296069 :: [ThePirateBay] :: [1fdd694] Search mode: Season
2016-11-02 15:10:25 DEBUG    SEARCHQUEUE-MANUAL-296069 :: [ThePirateBay] :: [1fdd694] Search string: Paul and Nick’s Big American Food Trip S01
2016-11-02 15:10:25 DEBUG    SEARCHQUEUE-MANUAL-296069 :: [ThePirateBay] :: [1fdd694] Searching only confirmed torrents
2016-11-02 15:10:25 DEBUG    SEARCHQUEUE-MANUAL-296069 :: [ThePirateBay] :: [1fdd694] GET URL: http://thepiratebay.se/search/Paul%20and%20Nick%E2%80%99s%20Big%20American%20Food%20Trip%20S01/0/3/200 [Status: 301]
2016-11-02 15:10:25 DEBUG    POSTPROCESSOR :: [1fdd694] Found matches set(['episode', 'season', 'year', 'video_codec'])
2016-11-02 15:10:25 DEBUG    POSTPROCESSOR :: [1fdd694] Matched hearing_impaired
2016-11-02 15:10:25 DEBUG    POSTPROCESSOR :: [1fdd694] Computed score 153 with final matches set(['episode', 'season', 'year', 'video_codec', 'hearing_impaired'])
2016-11-02 15:10:25 DEBUG    POSTPROCESSOR :: [1fdd694] Computing score of <OpenSubtitlesSubtitle '1955254294' [pt-BR]> for video <Episode ['Cordon', 2014, 1x10]> with {'hearing_impaired': False}
2016-11-02 15:10:25 DEBUG    POSTPROCESSOR :: [1fdd694] Using scores {'hash': 359, 'format': 7, 'series': 180, 'audio_codec': 3, 'year': 90, 'hearing_impaired': 1, 'episode': 30, 'season': 30, 'video_codec': 2, 'resolution': 2, 'release_group': 15}
2016-11-02 15:10:26 DEBUG    POSTPROCESSOR :: [1fdd694] Found matches set(['episode', 'year', 'season', 'video_codec'])
2016-11-02 15:10:26 DEBUG    POSTPROCESSOR :: [1fdd694] Matched hearing_impaired
2016-11-02 15:10:26 DEBUG    POSTPROCESSOR :: [1fdd694] Computed score 153 with final matches set(['episode', 'year', 'season', 'video_codec', 'hearing_impaired'])
2016-11-02 15:10:26 DEBUG    POSTPROCESSOR :: [1fdd694] Score 153 is below min_score (352)
2016-11-02 15:10:26 INFO     POSTPROCESSOR :: [1fdd694] No subtitles found for Cordon.S01E10.720p.iP.WEBRip.AAC2.0.H.264-EsQ.mkv with a minimum score of 352
2016-11-02 15:10:26 DEBUG    POSTPROCESSOR :: [1fdd694] 279271: Saving last subtitles search to database
2016-11-02 15:10:27 DEBUG    SEARCHQUEUE-MANUAL-296069 :: [ThePirateBay] :: [1fdd694] GET URL: https://thepiratebay.org/search/Paul%20and%20Nick%E2%80%99s%20Big%20American%20Food%20Trip%20S01/0/3/200 [Status: 200]
2016-11-02 15:10:27 DEBUG    SEARCHQUEUE-MANUAL-296069 :: [ThePirateBay] :: [1fdd694] Data returned from provider does not contain any confirmed torrents
2016-11-02 15:10:27 DEBUG    SEARCHQUEUE-MANUAL-296069 :: [ThePirateBay] :: [1fdd694] Search string: Paul and Nicks Big American Food Trip S01
2016-11-02 15:10:27 DEBUG    SEARCHQUEUE-MANUAL-296069 :: [ThePirateBay] :: [1fdd694] Searching only confirmed torrents
2016-11-02 15:10:27 DEBUG    SEARCHQUEUE-MANUAL-296069 :: [ThePirateBay] :: [1fdd694] GET URL: http://thepiratebay.se/search/Paul%20and%20Nicks%20Big%20American%20Food%20Trip%20S01/0/3/200 [Status: 301]
2016-11-02 15:10:28 INFO     POSTPROCESSOR :: [1fdd694] 279271: No subtitles found for Cordon S01E10
2016-11-02 15:10:28 DEBUG    POSTPROCESSOR :: [1fdd694] Transaction with 1 queries executed
2016-11-02 15:10:28 DEBUG    POSTPROCESSOR :: [1fdd694] 279271: Setter sets location to /media/extssd/Shows/Cordon/Season 01/Cordon.S01E10.720p.iP.WEBRip.AAC2.0.H.264-EsQ.mkv
2016-11-02 15:10:28 DEBUG    POSTPROCESSOR :: [1fdd694] Transaction with 1 queries executed
2016-11-02 15:10:28 DEBUG    POSTPROCESSOR :: [1fdd694] 279271: About to modify date of '/media/extssd/Shows/Cordon/Season 01/Cordon.S01E10.720p.iP.WEBRip.AAC2.0.H.264-EsQ.mkv' to show air date May 12,2014 (19:45)
2016-11-02 15:10:28 INFO     POSTPROCESSOR :: [1fdd694] 279271: Changed modify date of 'Cordon.S01E10.720p.iP.WEBRip.AAC2.0.H.264-EsQ.mkv' to show air date May 12,2014 (19:45)
2016-11-02 15:10:28 DEBUG    POSTPROCESSOR :: [1fdd694] Checking if /media/extssd/Shows/Cordon/Season 01/Cordon.S01E10.720p.iP.WEBRip.AAC2.0.H.264-EsQ.nfo exists: False
2016-11-02 15:10:28 DEBUG    SEARCHQUEUE-MANUAL-296069 :: [ThePirateBay] :: [1fdd694] GET URL: https://thepiratebay.org/search/Paul%20and%20Nicks%20Big%20American%20Food%20Trip%20S01/0/3/200 [Status: 200]
2016-11-02 15:10:29 DEBUG    SEARCHQUEUE-MANUAL-296069 :: [ThePirateBay] :: [1fdd694] Data returned from provider does not contain any confirmed torrents
2016-11-02 15:10:29 INFO     SEARCHQUEUE-MANUAL-296069 :: [FreshOnTV] :: [1fdd694] Performing season pack search for Paul and Nick’s Big American Food Trip
2016-11-02 15:10:29 DEBUG    SEARCHQUEUE-MANUAL-296069 :: [FreshOnTV] :: [1fdd694] Search mode: Season
2016-11-02 15:10:29 DEBUG    SEARCHQUEUE-MANUAL-296069 :: [FreshOnTV] :: [1fdd694] Search string: Paul and Nick’s Big American Food Trip S01
2016-11-02 15:10:30 DEBUG    POSTPROCESSOR :: [1fdd694] Parsed '/media/extssd/Shows/Cordon/Season 01/Cordon.S01E10.720p.iP.WEBRip.AAC2.0.H.264-EsQ' into title: Cordon, season: 1, episode: [10], screen_size: 720p, format: WEBRip, audio_codec: AAC, audio_channels: 2.0, video_codec: h264, release_group: EsQ, type: episode, absolute_episode: [], quality: 720p WEB-DL
2016-11-02 15:10:30 DEBUG    SEARCHQUEUE-MANUAL-296069 :: [FreshOnTV] :: [1fdd694] GET URL: https://freshon.tv/browse.php?incldead=0&words=0&cat=0&search=Paul%20and%20Nick%E2%80%99s%20Big%20American%20Food%20Trip%20S01 [Status: 200]
2016-11-02 15:10:31 DEBUG    POSTPROCESSOR :: [1fdd694] Parsed 'Cordon.S01E10.720p.iP.WEBRip.AAC2.0.H.264-EsQ' into title: Cordon, season: 1, episode: [10], screen_size: 720p, format: WEBRip, audio_codec: AAC, audio_channels: 2.0, video_codec: h264, release_group: EsQ, type: episode, absolute_episode: [], quality: 720p WEB-DL
2016-11-02 15:10:31 DEBUG    POSTPROCESSOR :: [1fdd694] Found codec for Cordon Episode 10
2016-11-02 15:10:31 DEBUG    POSTPROCESSOR :: [1fdd694] 279271: Formatting pattern: %SN - S%0SE%0E - %EN -> Cordon - S01E10 - Episode 10
2016-11-02 15:10:31 DEBUG    POSTPROCESSOR :: [1fdd694] Metadata provider KODI 12+ creating episode metadata for Cordon - S01E10 - Episode 10
2016-11-02 15:10:35 DEBUG    POSTPROCESSOR :: [1fdd694] Creating metadata for episode S01E10
2016-11-02 15:10:35 DEBUG    POSTPROCESSOR :: [1fdd694] Writing episode nfo file to /media/extssd/Shows/Cordon/Season 01/Cordon.S01E10.720p.iP.WEBRip.AAC2.0.H.264-EsQ.nfo
2016-11-02 15:10:35 ERROR    POSTPROCESSOR :: [1fdd694] Unable to write file to /media/extssd/Shows/Cordon/Season 01/Cordon.S01E10.720p.iP.WEBRip.AAC2.0.H.264-EsQ.nfo: Exception generated: [Errno 28] No space left on device: '/media/extssd/Shows/Cordon/Season 01/Cordon.S01E10.720p.iP.WEBRip.AAC2.0.H.264-EsQ.nfo'
Traceback (most recent call last):
  File "/home/home/SickRage/medusa/metadata/generic.py", line 449, in write_ep_file
    nfo_file = io.open(nfo_file_path, 'wb')
  File "/home/home/SickRage/medusa/init/filesystem.py", line 85, in <lambda>
    return lambda *args, **kwargs: handle_output(f(*[handle_arg(arg) for arg in args], **{k: handle_arg(arg) for k, arg in kwargs.items()}))
IOError: [Errno 28] No space left on device: '/media/extssd/Shows/Cordon/Season 01/Cordon.S01E10.720p.iP.WEBRip.AAC2.0.H.264-EsQ.nfo'

# Fixed code
def handle(err, message="", *args, **kwargs):
    """Single entry point to handle unhandled exceptions.

    :param err:
    :param message:
    :type err: Exception
    """
    m = message.format(*args, **kwargs) + ": " if message else ""
    if isinstance(err, EnvironmentError):
        if err.errno == 28:
            logger.warning("{m}Out of disk space: {error_msg}", m=m, error_msg=err)
        elif err.errno == 13:
            logger.warning("{m}Permission denied: {error_msg}", m=m, error_msg=err)
        else:
            logger.warning("{m}Environment error: {error_msg}", m=m, error_msg=err)
    else:
        logger.exception("{m}Exception generated: {error_msg}", m=m, error_msg=err)