From 9ad63287eb5ba93b80b9e37619924d3d43e550a7 Mon Sep 17 00:00:00 2001 From: Felix Yan Date: Tue, 9 Jan 2018 11:32:50 +0800 Subject: [PATCH] Handle exception for no-tag situation Before: ``` [E 01-09 11:26:03.736 core:132] unexpected error happened with dnscrypt-proxy Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/nvchecker/core.py", line 128, in future_done version = fu.result() File "/usr/lib/python3.6/site-packages/nvchecker/get_version.py", line 43, in get_version version = await func(name, conf) File "/usr/lib/python3.6/site-packages/nvchecker/source/github.py", line 43, in get_version version = data[-1] IndexError: list index out of range ``` After: ``` [E 01-09 11:32:35.308 github:50] dnscrypt-proxy: No tag found in upstream repository. ``` --- nvchecker/source/github.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nvchecker/source/github.py b/nvchecker/source/github.py index 526576b..77c2a69 100644 --- a/nvchecker/source/github.py +++ b/nvchecker/source/github.py @@ -2,6 +2,7 @@ # Copyright (c) 2013-2017 lilydjwg , et al. import os +import logging from . import session from ..sortversion import sort_version_keys @@ -10,6 +11,8 @@ GITHUB_URL = 'https://api.github.com/repos/%s/commits?sha=%s' GITHUB_LATEST_RELEASE = 'https://api.github.com/repos/%s/releases/latest' GITHUB_MAX_TAG = 'https://api.github.com/repos/%s/tags' +logger = logging.getLogger(__name__) + async def get_version(name, conf): repo = conf.get('github') br = conf.get('branch', 'master') @@ -36,10 +39,16 @@ async def get_version(name, conf): async with session.get(url, headers=headers, **kwargs) as res: data = await res.json() if use_latest_release: + if 'tag_name' not in data: + logger.error('%s: No tag found in upstream repository.', name) + return version = data['tag_name'] elif use_max_tag: data = [tag["name"] for tag in data if tag["name"] not in ignored_tags] data.sort(key=sort_version_key) + if not len(data): + logger.error('%s: No tag found in upstream repository.', name) + return version = data[-1] else: # YYYYMMDD.HHMMSS