aboutsummaryrefslogtreecommitdiffstats
path: root/snekbox.py
diff options
context:
space:
mode:
authorGravatar Christopher Baklid <[email protected]>2018-07-24 22:05:09 +0200
committerGravatar Christopher Baklid <[email protected]>2018-07-24 22:05:09 +0200
commit68f139fbe564425f8e56d1e18120654061981fe1 (patch)
treee822cbefffc65b120efbdb7016ef52da5f77b14e /snekbox.py
parentmissing comma (diff)
update pipfile lock, handle value error, show error codes when unhandled
Diffstat (limited to 'snekbox.py')
-rw-r--r--snekbox.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/snekbox.py b/snekbox.py
index 2d3fc66..f74095b 100644
--- a/snekbox.py
+++ b/snekbox.py
@@ -45,13 +45,15 @@ class Snekbox(object):
'--cgroup_mem_max=52428800',
'--quiet', '--',
self.python_binary, '-ISq', '-c', cmd]
-
- proc = subprocess.Popen(args,
+ try:
+ proc = subprocess.Popen(args,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=self.env,
universal_newlines=True)
+ except ValueError:
+ return 'ValueError: embedded null byte'
stdout, stderr = proc.communicate()
if proc.returncode == 0:
@@ -67,17 +69,17 @@ class Snekbox(object):
except IndexError:
output = ''
- elif proc.returncode == 11:
- output = 'segfaulted, nice work!'
-
elif proc.returncode == 109:
- output = 'timed out or memory limit exceeded'
+ return 'timed out or memory limit exceeded'
elif proc.returncode == 255:
- output = 'permission denied (root required)'
+ return 'permission denied (root required)'
+
+ elif proc.returncode:
+ return f'unknown error, code: {proc.returncode}'
else:
- output = 'unknown error'
+ return 'unknown error, no error code'
return output