Skip to content

Commit

Permalink
Improved error handling (close #294)
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Apr 25, 2021
1 parent 80db886 commit 1566ef7
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 17 deletions.
1 change: 1 addition & 0 deletions CB/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ def bulk_check_checksum_callback(self, result):
self.checksumCache[result[0]] = result[1]

def bulk_check_checksum(self, addons, pbar):
self.checksumCache = {}
with Pool(processes=min(60, os.cpu_count() or 1)) as pool:
workers = []
for addon in addons:
Expand Down
7 changes: 5 additions & 2 deletions CB/CurseForge.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ def __init__(self, url, project, checkcache, clienttype, allowdev):
if project in checkcache:
self.payload = checkcache[project]
else:
self.payload = requests.get(f'https://addons-ecs.forgesvc.net/api/v2/addon/{project}',
headers=HEADERS, timeout=5)
try:
self.payload = requests.get(f'https://addons-ecs.forgesvc.net/api/v2/addon/{project}',
headers=HEADERS, timeout=5)
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
raise RuntimeError(f'{url}\nCurseForge API failed to respond.')
if self.payload.status_code == 404 or self.payload.status_code == 500:
raise RuntimeError(f'{url}\nThis might be a temporary issue with CurseForge API or the project was '
f'removed/renamed. In this case, uninstall it (and reinstall if it still exists) '
Expand Down
12 changes: 9 additions & 3 deletions CB/GitHub.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ class GitHubAddon:
@retry()
def __init__(self, url, clienttype):
project = url.replace('https://github.com/', '')
self.payload = requests.get(f'https://api.github.com/repos/{project}/releases', headers=HEADERS, timeout=5)
try:
self.payload = requests.get(f'https://api.github.com/repos/{project}/releases', headers=HEADERS, timeout=5)
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
raise RuntimeError(f'{project}\nGitHub API failed to respond.')
if self.payload.status_code == 404:
raise RuntimeError(url)
else:
Expand Down Expand Up @@ -72,8 +75,11 @@ def install(self, path):
class GitHubAddonRaw:
@retry()
def __init__(self, project, branch, targetdirs):
self.payload = requests.get(f'https://api.github.com/repos/{project}/branches/{branch}',
headers=HEADERS, timeout=5)
try:
self.payload = requests.get(f'https://api.github.com/repos/{project}/branches/{branch}',
headers=HEADERS, timeout=5)
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
raise RuntimeError(f'{project}\nGitHub API failed to respond.')
if self.payload.status_code == 404:
raise RuntimeError(f'{project}\nTarget branch don\'t exist.')
else:
Expand Down
7 changes: 5 additions & 2 deletions CB/GitLab.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
class GitLabAddon:
@retry()
def __init__(self, name, projectid, path, branch):
self.payload = requests.get(f'https://git.tukui.org/api/v4/projects/{projectid}/repository/branches/{branch}',
headers=HEADERS, timeout=5)
try:
self.payload = requests.get(f'https://git.tukui.org/api/v4/projects/{projectid}/repository/branches/'
f'{branch}', headers=HEADERS, timeout=5)
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
raise RuntimeError(f'{name}\nTukui GitLab API failed to respond.')
if self.payload.status_code == 404:
raise RuntimeError(name)
else:
Expand Down
7 changes: 5 additions & 2 deletions CB/Tukui.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ class TukuiAddon:
@retry()
def __init__(self, url, checkcache, special=None):
if special:
self.payload = requests.get(f'https://www.tukui.org/api.php?ui={special}',
headers=HEADERS, timeout=5).json()
try:
self.payload = requests.get(f'https://www.tukui.org/api.php?ui={special}',
headers=HEADERS, timeout=5).json()
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
raise RuntimeError(f'{url}\nTukui API failed to respond.')
else:
project = re.findall(r'\d+', url)[0]
for addon in checkcache:
Expand Down
7 changes: 5 additions & 2 deletions CB/WoWInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ def __init__(self, url, checkcache):
if project in checkcache:
self.payload = checkcache[project]
else:
self.payload = requests.get(f'https://api.mmoui.com/v3/game/WOW/filedetails/{project}.json',
headers=HEADERS, timeout=5).json()
try:
self.payload = requests.get(f'https://api.mmoui.com/v3/game/WOW/filedetails/{project}.json',
headers=HEADERS, timeout=5).json()
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
raise RuntimeError(f'{url}\nWoWInterface API failed to respond.')
if 'ERROR' in self.payload:
raise RuntimeError(f'{url}\nThis might be a temporary error or this project is not supported '
f'by WoWInterface API.')
Expand Down
14 changes: 8 additions & 6 deletions CurseBreaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,6 @@ def c_uninstall(self, args):

def c_update(self, args, addline=False, update=True, force=False, provider=False, reversecompact=False):
compact = not self.core.config['CompactMode'] if reversecompact else self.core.config['CompactMode']
if len(self.core.cfCache) > 0 or len(self.core.wowiCache) > 0:
self.core.cfCache = {}
self.core.wowiCache = {}
self.core.checksumCache = {}
if args:
addons = self.parse_args(args)
compacted = -1
Expand All @@ -505,7 +501,10 @@ def c_update(self, args, addline=False, update=True, force=False, provider=False
auto_refresh=False, console=None if self.headless else self.console) as progress:
task = progress.add_task('', total=len(addons))
if not args:
self.core.bulk_check(addons)
try:
self.core.bulk_check(addons)
except RuntimeError:
pass
self.core.bulk_check_checksum(addons, progress)
while not progress.finished:
for addon in addons:
Expand Down Expand Up @@ -724,7 +723,10 @@ def c_show(self, args):
if args.startswith('dependencies'):
addons = sorted(list(filter(lambda k: k['URL'].startswith('https://www.curseforge.com/wow/addons/'),
self.core.config['Addons'])), key=lambda k: k['Name'].lower())
self.core.bulk_check(addons)
try:
self.core.bulk_check(addons)
except RuntimeError:
pass
for addon in addons:
dependencies = DependenciesParser(self.core)
name, _, _, _, _, _, _, _, _, _, deps, _ = self.core.update_addon(addon['URL'], False, False)
Expand Down

0 comments on commit 1566ef7

Please sign in to comment.