1 parent
83c411b308
commit
688188777f
4 files changed
+79
-13
No files matched your search
@@ -1497,17 +1497,33 @@ class SoftwareUpdatePlugin(
|
||||
update_possible = False
|
||||
information["needs_online"] = True
|
||||
except exceptions.UnknownCheckType:
|
||||
self._logger.warning("Unknown check type %s for %s" % (check["type"], target))
|
||||
self._logger.warning(
|
||||
"Unknown check type {} for {}".format(check["type"], target)
|
||||
)
|
||||
update_possible = False
|
||||
error = "unknown_check"
|
||||
except exceptions.NetworkError:
|
||||
self._logger.warning(
|
||||
"Could not check %s for updates due to a network error" % target
|
||||
"Could not check {} for updates due to a network error".format(target)
|
||||
)
|
||||
update_possible = False
|
||||
error = "network"
|
||||
except exceptions.RateLimitCheckError as exc:
|
||||
self._logger.warning(
|
||||
"Could not check {} for updates due to running into a rate limit: {}".format(
|
||||
target, exc
|
||||
)
|
||||
)
|
||||
update_possible = False
|
||||
error = "ratelimit"
|
||||
except exceptions.CheckError:
|
||||
self._logger.warning(
|
||||
"Could not check {} for updates due to a check error".format(target)
|
||||
)
|
||||
update_possible = False
|
||||
error = "check"
|
||||
except Exception:
|
||||
self._logger.exception("Could not check %s for updates" % target)
|
||||
self._logger.exception("Could not check {} for updates".format(target))
|
||||
update_possible = False
|
||||
error = "unknown"
|
||||
else:
|
||||
|
||||
@@ -37,11 +37,30 @@ class NetworkError(Exception):
|
||||
return "NetworkError"
|
||||
|
||||
|
||||
class CheckError(Exception):
|
||||
def __init__(self, message):
|
||||
self.message = message
|
||||
|
||||
def __str__(self):
|
||||
return self.message
|
||||
|
||||
|
||||
class RateLimitCheckError(CheckError):
|
||||
def __init__(self, message, remaining=None, limit=None, reset=None):
|
||||
super(RateLimitCheckError, self).__init__(message)
|
||||
self.remaining = remaining
|
||||
self.limit = limit
|
||||
self.reset = reset
|
||||
|
||||
|
||||
class UpdateError(Exception):
|
||||
def __init__(self, message, data):
|
||||
self.message = message
|
||||
self.data = data
|
||||
|
||||
def __str__(self):
|
||||
return self.message
|
||||
|
||||
|
||||
class ScriptError(Exception):
|
||||
def __init__(self, returncode, stdout, stderr):
|
||||
|
||||
@@ -577,6 +577,14 @@ $(function () {
|
||||
case "network": {
|
||||
return gettext("Network error while checking for update");
|
||||
}
|
||||
case "ratelimit": {
|
||||
return gettext(
|
||||
"Rate limit exceeded while checking for update, please try again later"
|
||||
);
|
||||
}
|
||||
case "check": {
|
||||
return gettext("Check internal error while checking for update");
|
||||
}
|
||||
case "unknown": {
|
||||
return gettext(
|
||||
"Unknown error while checking for update, please check the logs"
|
||||
|
||||
@@ -5,6 +5,7 @@ __author__ = "Gina Häußge <osd@foosel.net>"
|
||||
__license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html"
|
||||
__copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
||||
|
||||
from ..exceptions import RateLimitCheckError
|
||||
from . import ( # noqa: F401
|
||||
always_current,
|
||||
bitbucket_commit,
|
||||
@@ -20,21 +21,43 @@ from . import ( # noqa: F401
|
||||
)
|
||||
|
||||
|
||||
class GithubRateLimitCheckError(RateLimitCheckError):
|
||||
def __init__(self, remaining, ratelimit, reset):
|
||||
if reset:
|
||||
message = "Github rate limit exceeded, reset at {}".format(reset)
|
||||
else:
|
||||
message = "Github rate limit exceeded"
|
||||
super(GithubRateLimitCheckError, self).__init__(
|
||||
message, remaining=remaining, limit=ratelimit, reset=reset
|
||||
)
|
||||
|
||||
|
||||
def log_github_ratelimit(logger, r):
|
||||
ratelimit = (
|
||||
r.headers["X-RateLimit-Limit"] if "X-RateLimit-Limit" in r.headers else "?"
|
||||
)
|
||||
remaining = (
|
||||
r.headers["X-RateLimit-Remaining"]
|
||||
if "X-RateLimit-Remaining" in r.headers
|
||||
else "?"
|
||||
)
|
||||
try:
|
||||
ratelimit = int(r.headers.get("X-RateLimit-Limit", None))
|
||||
except ValueError:
|
||||
ratelimit = None
|
||||
|
||||
try:
|
||||
remaining = int(r.headers.get("X-RateLimit-Remaining", None))
|
||||
except ValueError:
|
||||
remaining = None
|
||||
|
||||
reset = r.headers["X-RateLimit-Reset"] if "X-RateLimit-Reset" in r.headers else None
|
||||
try:
|
||||
import time
|
||||
|
||||
reset = time.strftime("%Y-%m-%d %H:%M", time.gmtime(int(reset)))
|
||||
except Exception:
|
||||
reset = "?"
|
||||
reset = None
|
||||
|
||||
logger.debug("Github rate limit: %s/%s, reset at %s" % (remaining, ratelimit, reset))
|
||||
logger.debug(
|
||||
"Github rate limit: {}/{}, reset at {}".format(
|
||||
remaining if remaining is not None else "?",
|
||||
ratelimit if ratelimit is not None else "?",
|
||||
reset if reset is not None else "?",
|
||||
)
|
||||
)
|
||||
|
||||
if remaining == 0:
|
||||
raise GithubRateLimitCheckError(remaining, ratelimit, reset)
|
||||
Reference in new issue
Block a user