Prevent simple errors from killing containers

This commit is contained in:
1computer1 2019-06-01 01:21:22 -04:00
parent 2f38bc640c
commit 0acb75aad6
27 changed files with 42 additions and 36 deletions

View file

@ -1,6 +1,6 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.apl
apl --OFF -s -f program.apl
apl --OFF -s -f program.apl || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,6 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.sh
bash program.sh
bash program.sh || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1 +1 @@
printf %s "$1" | bf
printf %s "$1" | bf || true

View file

@ -1,6 +1,6 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.c
gcc program.c -o program && ./program
gcc program.c -o program && ./program || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,6 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.clj
clojure program.clj
clojure program.clj || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,6 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.cpp
g++ program.cpp -o program && ./program
g++ program.cpp -o program && ./program || true
cd .. && rm -rf "$CODEDIR"

View file

@ -4,7 +4,7 @@ else
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.cs
csc program.cs >/dev/null && mono program.exe
csc program.cs >/dev/null && mono program.exe || true
cd .. && rm -rf "$CODEDIR"
fi

View file

@ -1,6 +1,6 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.exs
elixir program.exs
elixir program.exs || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,6 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.fs
fsharpc --optimize- program.fs >/dev/null && mono program.exe
fsharpc --optimize- program.fs >/dev/null && mono program.exe || true
cd .. && rm -rf "$CODEDIR"

View file

@ -2,6 +2,6 @@ mkdir "$CODEDIR" && cd "$CODEDIR"
export GOCACHE=/tmp/"$CODEDIR"/cache
printf %s "$1" > program.go
go run program.go
go run program.go || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,10 +1,10 @@
if [ "$EVAL_EXPR" = "true" ]; then
ghc -e "$1"
ghc -e "$1" || true
else
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.hs
ghc -e main program.hs
ghc -e main program.hs || true
cd .. && rm -rf "$CODEDIR"
fi

View file

@ -1,6 +1,6 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > Main.java
javac Main.java && java Main
javac Main.java && java Main || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,5 +1,5 @@
if [ "$EVAL_HARMONY" = "true" ]; then
printf %s "$1" | node --harmony -p
printf %s "$1" | node --harmony -p || true
else
printf %s "$1" | node -p
printf %s "$1" | node -p || true
fi

View file

@ -1,5 +1,5 @@
if [ "$EVAL_EXPR" = "true" ]; then
printf %s "$1" | julia -E
printf %s "$1" | julia -E || true
else
printf %s "$1" | julia -e
printf %s "$1" | julia -e || true
fi

View file

@ -1,6 +1,6 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.lua
lua5.3 program.lua
lua5.3 program.lua || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,6 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.ml
ocamlopt -cclib --static -o program program.ml && ./program
ocamlopt -cclib --static -o program program.ml && ./program || true
cd .. && rm -rf "$CODEDIR"

View file

@ -6,10 +6,9 @@ printf %s "$1" > program.pas
res="$(fpc program.pas 2>&1)"
if [ $? -eq 0 ]; then
./program
./program || true
else
printf %s "$res"
exit 1
fi
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,6 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.pl
perl program.pl
perl program.pl || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1 +1 @@
printf %s "$1" | php -r
printf %s "$1" | php -r || true

View file

@ -1,6 +1,6 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.pl
swipl --quiet program.pl
swipl --quiet program.pl || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,6 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.py
python program.py
python program.py || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,6 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.py
python program.py
python program.py || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,6 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.rkt
racket program.rkt
racket program.rkt || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,6 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.rb
ruby program.rb
ruby program.rb || true
cd .. && rm -rf "$CODEDIR"

View file

@ -1,6 +1,6 @@
mkdir "$CODEDIR" && cd "$CODEDIR"
printf %s "$1" > program.rs
rustc -C opt-level=0 --color never program.rs && ./program
rustc -C opt-level=0 --color never program.rs && ./program || true
cd .. && rm -rf "$CODEDIR"

View file

@ -29,7 +29,13 @@ class MessageInvalidListener extends Listener {
let errored = false;
let result;
try {
result = await this.client.languageHandler.evalCode(parse);
const { stdout, stderr } = await this.client.languageHandler.evalCode(parse);
if (stderr) {
errored = true;
result = stderr;
} else {
result = stdout;
}
} catch (e) {
errored = true;
result = e.message;

View file

@ -155,14 +155,15 @@ class LanguageHandler extends AkairoHandler {
}, timeout);
}
let data = '';
let stdout = '';
let stderr = '';
let error;
proc.stdout.on('data', chunk => {
data += chunk;
stdout += chunk;
});
proc.stderr.on('data', chunk => {
data += chunk;
stderr += chunk;
});
proc.on('error', e => {
@ -174,12 +175,12 @@ class LanguageHandler extends AkairoHandler {
handled = true;
if (status !== 0 || error) {
if (!error) {
error = new Error(data || 'Something went wrong');
error = new Error(stderr || 'Something went wrong');
}
reject(error);
} else {
resolve(data);
resolve({ stdout, stderr });
}
}
});