Skip to content

Commit

Permalink
log viewer now handles empty logfiles etter
Browse files Browse the repository at this point in the history
  • Loading branch information
staffanm committed Jul 31, 2018
1 parent 6492499 commit 22f3095
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions ferenda/devel.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,12 @@ def handle_logs(self, environ, params):
logdir = self.repo.config.datadir + os.sep + "logs"
def firstline(f):
with open(logdir+os.sep+f) as fp:
# trim uninteresting things from start and end
return fp.readline().split(" ", 3)[-1].rsplit(" (", 1)[0]
# trim uninteresting things from start and end
l = fp.readline().split(" ", 3)[-1].rsplit(" (", 1)[0]
if l.strip():
return l
else:
return "[log is empty?]"

def linkelement(f):
href = environ['PATH_INFO'] + "?file=" + f
Expand Down
3 changes: 2 additions & 1 deletion ferenda/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ def robust_fetch(method, url, logger, attempts=5, sleep=1, raise_for_status=True
*args, **kwargs):
fetched = False
lastexception = None
response = None
try:
while (not fetched) and (attempts > 0):
try:
Expand All @@ -846,7 +847,7 @@ def robust_fetch(method, url, logger, attempts=5, sleep=1, raise_for_status=True
"Failed to fetch %s: err %s (%s remaining attempts)" %
(url, e, attempts))
lastexception = e
if response.status_code >= 400 and response.status_code != 404:
if response and response.status_code >= 400 and response.status_code != 404:
fetched = False # let's retry even for 400 or 500 class errors, maybe it'll go better in a second
logger.warning("Failed to fetch %s: status %s (%s remaining attempts)" % (url, response.status_code, attempts))
attempts -= 1
Expand Down

0 comments on commit 22f3095

Please sign in to comment.