From 02988d12c5c3ba87c3444d29f6f8137e27289f29 Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Thu, 15 Aug 2019 23:05:21 +0200 Subject: [PATCH] Catch exceptions from failed ps2edit calls --- boxes/formats.py | 4 ++++ scripts/boxesserver | 16 +++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/boxes/formats.py b/boxes/formats.py index 962a175..29a62a4 100644 --- a/boxes/formats.py +++ b/boxes/formats.py @@ -113,6 +113,10 @@ class Formats: if err: # XXX show stderr output + try: + os.unlink(tmpfile) + except: + pass raise ValueError("Conversion failed. pstoedit returned %i" % err) os.rename(tmpfile, filename) diff --git a/scripts/boxesserver b/scripts/boxesserver index 6f142c8..4338cf7 100755 --- a/scripts/boxesserver +++ b/scripts/boxesserver @@ -411,15 +411,21 @@ b""" start_response(status, headers) return self.errorMessage(name, e) - start_response(status, - box.formats.http_headers.get( - box.format, - [('Content-type', 'application/unknown; charset=utf-8')])) fd, box.output = tempfile.mkstemp() box.metadata["url"] = self.getURL(environ) box.open() box.render() - box.close() + try: + box.close() + except ValueError as e: + start_response("500 Internal Server Error", + [('Content-type', 'text/plain; charset=utf-8')]) + return([b"Server Error\n\n", str(e).encode("utf-8")]) + + start_response(status, + box.formats.http_headers.get( + box.format, + [('Content-type', 'application/unknown; charset=utf-8')])) result = open(box.output).readlines() os.close(fd) os.remove(box.output)