Skip to content
Permalink
Browse files
Fix getnikola/plugins#282 — more informative errors for JSON parse fa…
…ilures

Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jul 24, 2018
1 parent f28f419 commit e023540b8e9100704876186f301d10d73cfed8b9
Showing with 35 additions and 13 deletions.
  1. +2 −0 CHANGES.txt
  2. +16 −6 nikola/plugins/command/plugin.py
  3. +17 −7 nikola/plugins/command/theme.py
@@ -8,6 +8,8 @@ Features

* Show the filename of the missing file when ``nikola serve`` can't
find a file (i.e. when an 404 error occurs).
* Better error messages for JSON download failures in ``nikola
plugin`` and ``nikola theme`` (Issue getnikola/plugins#282)

Bugfixes
--------
@@ -27,6 +27,7 @@
"""Manage plugins."""

import io
import json.decoder
import os
import sys
import shutil
@@ -338,10 +339,19 @@ def get_json(self, url):
"""Download the JSON file with all plugins."""
if self.json is None:
try:
self.json = requests.get(url).json()
except requests.exceptions.SSLError:
LOGGER.warning("SSL error, using http instead of https (press ^C to abort)")
time.sleep(1)
url = url.replace('https', 'http', 1)
self.json = requests.get(url).json()
try:
self.json = requests.get(url).json()
except requests.exceptions.SSLError:
LOGGER.warning("SSL error, using http instead of https (press ^C to abort)")
time.sleep(1)
url = url.replace('https', 'http', 1)
self.json = requests.get(url).json()
except json.decoder.JSONDecodeError as e:
LOGGER.error("Failed to decode JSON data in response from server.")
LOGGER.error("JSON error encountered: " + str(e))
LOGGER.error("This issue might be caused by server-side issues, or by to unusual activity in your "
"network (as determined by CloudFlare). Please visit https://plugins.getnikola.com/ in "
"a browser.")
sys.exit(2)

return self.json
@@ -26,8 +26,9 @@

"""Manage themes."""

import os
import io
import json.decoder
import os
import shutil
import time
import requests
@@ -374,10 +375,19 @@ def get_json(self, url):
"""Download the JSON file with all plugins."""
if self.json is None:
try:
self.json = requests.get(url).json()
except requests.exceptions.SSLError:
LOGGER.warning("SSL error, using http instead of https (press ^C to abort)")
time.sleep(1)
url = url.replace('https', 'http', 1)
self.json = requests.get(url).json()
try:
self.json = requests.get(url).json()
except requests.exceptions.SSLError:
LOGGER.warning("SSL error, using http instead of https (press ^C to abort)")
time.sleep(1)
url = url.replace('https', 'http', 1)
self.json = requests.get(url).json()
except json.decoder.JSONDecodeError as e:
LOGGER.error("Failed to decode JSON data in response from server.")
LOGGER.error("JSON error encountered:" + str(e))
LOGGER.error("This issue might be caused by server-side issues, or by to unusual activity in your "
"network (as determined by CloudFlare). Please visit https://themes.getnikola.com/ in "
"a browser.")
sys.exit(2)

return self.json

0 comments on commit e023540

Please sign in to comment.