Skip to content

Commit dd48d0e

Browse files
committed
Proper error reporting of missing javac
1 parent a79ceb6 commit dd48d0e

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ A web-based Java compiler frontend to play with single-source console programs.
1212
- A modern browser
1313
- Supporting [`localStorage`][], [`history.replaceState`][], [`const`][], [`box-sizing`][], [`flex`][]
1414
- Supposedly Firefox 29+, Chrome 29+, Edge, Safari 9+, IE 11, Opera 17+
15+
- `javac` and `java` in `PATH` when executing server ([example batch file](https://gist.github.com/johncf/a98cd3aa49491c5f58372566883e7810) which does this).
1516

1617
[`localStorage`]: https://caniuse.com/#feat=const
1718
[`history.replaceState`]: https://caniuse.com/#feat=history

compiler.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,18 @@ def __init__(self, source, dirpath, callbacks):
3333
self._cbs = callbacks
3434

3535
def _compile(self):
36-
return Popen(["javac", "-Xlint", self._name + ".java"], cwd=self._dir, stdout=PIPE, stderr=STDOUT)
36+
try:
37+
return Popen(["javac", "-Xlint", self._name + ".java"], cwd=self._dir, stdout=PIPE, stderr=STDOUT)
38+
except FileNotFoundError as e:
39+
print("Error:", e.strerror)
40+
return None
3741

3842
def _execute(self):
39-
return Popen(["java", self._name], cwd=self._dir, stdin=PIPE, stdout=PIPE, stderr=PIPE)
43+
try:
44+
return Popen(["java", self._name], cwd=self._dir, stdin=PIPE, stdout=PIPE, stderr=PIPE)
45+
except FileNotFoundError as e:
46+
print("Error:", e.strerror)
47+
return None
4048

4149
def spawn_bg(self):
4250
t = _spawn(_main, args=(self,))
@@ -74,6 +82,9 @@ def read2Q(key, stream, notifq, limit_size=4096, limit_lines=256):
7482

7583
def _main(program):
7684
proc = program._compile()
85+
if proc is None:
86+
program._cbs.error("Backend did not find 'javac' in PATH.")
87+
return
7788
outt = _spawn(read2Q, args=('stdout', proc.stdout, program._queue))
7889
outt.start()
7990
done = False

server.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def stdin_ack(self, data):
4646
def done(self, ecode):
4747
self._emit('done', {'ecode': ecode})
4848

49+
def error(self, msg):
50+
self._emit('backend_error', {'description': msg})
51+
4952
def reset_dir(path):
5053
if os.path.isdir(path):
5154
for root, dirs, files in os.walk(path, topdown=False):

static/js/main.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ const compile_button = document.getElementById("compile");
6969
const kill_button = document.getElementById("kill");
7070
const stdin_input = document.getElementById("stdin");
7171

72+
function fatalError(msg) {
73+
logClear();
74+
logAppend(msg, true);
75+
compile_button.disabled = true;
76+
kill_button.disabled = true;
77+
stdin_input.disabled = true;
78+
}
79+
7280
const socket = io("/compiler");
7381
socket.on('connect', function() {
7482
logAppend("Click \"Compile & Execute\" when ready.", true);
@@ -77,11 +85,10 @@ socket.on('connect', function() {
7785
stdin_input.disabled = true;
7886
});
7987
socket.on('disconnect', function() {
80-
logClear();
81-
logAppend("Connection with compiler lost. Please rerun the backend.", true);
82-
compile_button.disabled = true;
83-
kill_button.disabled = true;
84-
stdin_input.disabled = true;
88+
fatalError("Connection with compiler lost. Please rerun the backend.");
89+
});
90+
socket.on('backend_error', function(e) {
91+
fatalError(e.description);
8592
});
8693
socket.on('started', function(msg) {
8794
logAppend("Compiling...", true);

0 commit comments

Comments
 (0)