Skip to content
This repository was archived by the owner on Jun 26, 2026. It is now read-only.

Commit 4d37eed

Browse files
matejvasekclaude
andcommitted
feat: add error server for failed backend compilation
When the Go backend fails to compile, the file watcher now starts a lightweight error server (errserver) that returns HTTP 500 with the compilation error as JSON {"message": "..."}. The OCP console parses this format automatically, so the UI displays the actual compiler output instead of a generic "Internal Server Error". Signed-off-by: Matej Vašek <matejvasek@gmail.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e575749 commit 4d37eed

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

backend/cmd/errserver/main.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"flag"
6+
"fmt"
7+
"log"
8+
"net/http"
9+
"os"
10+
)
11+
12+
func main() {
13+
port := flag.Int("port", 8080, "HTTP server port")
14+
msgFile := flag.String("msg-file", "", "file containing the error message to serve")
15+
flag.Parse()
16+
17+
msg, err := os.ReadFile(*msgFile)
18+
if err != nil {
19+
log.Fatalf("Failed to read message file: %v", err)
20+
}
21+
22+
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
23+
w.Header().Set("Content-Type", "application/json")
24+
w.WriteHeader(http.StatusInternalServerError)
25+
json.NewEncoder(w).Encode(map[string]string{"message": string(msg)})
26+
})
27+
28+
log.Printf("Serving compilation error on :%d", *port)
29+
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil))
30+
}

init.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ EOF
7878
start_backend() {
7979
echo "Building Go backend..."
8080
(cd backend && go build -buildvcs=false -o ../bin/backend .)
81+
(cd backend && go build -buildvcs=false -o ../bin/errserver ./cmd/errserver)
8182
echo "Starting Go backend..."
8283
./bin/backend --http-port "$BACKEND_PORT" >>"$LOG_DIR/backend.log" 2>&1 &
8384
echo $! > "$PID_DIR/backend.pid"
@@ -96,19 +97,27 @@ start_backend_watcher() {
9697
sleep 1 # debounce
9798

9899
echo "[watcher] Detected change, rebuilding backend..."
99-
if (cd backend && go build -buildvcs=false -o ../bin/backend-tmp .); then
100-
old_pid=$(cat "$PID_DIR/backend.pid" 2>/dev/null || true)
100+
old_pid=$(cat "$PID_DIR/backend.pid" 2>/dev/null || true)
101+
if build_output=$(cd backend && go build -buildvcs=false -o ../bin/backend-tmp . 2>&1); then
101102
if [ -n "$old_pid" ]; then
102-
kill "$old_pid" 2>/dev/null || true
103+
kill_tree "$old_pid" 2>/dev/null || true
103104
while kill -0 "$old_pid" 2>/dev/null; do sleep 0.1; done
104105
fi
105106
mv bin/backend-tmp bin/backend
106107
./bin/backend --http-port "$BACKEND_PORT" >>"$LOG_DIR/backend.log" 2>&1 &
107108
echo $! > "$PID_DIR/backend.pid"
108109
echo "[watcher] Backend restarted (PID $!)."
109110
else
110-
echo "[watcher] Build failed. Keeping current backend running."
111+
echo "[watcher] Build failed. Starting error server."
112+
echo "$build_output"
111113
rm -f bin/backend-tmp
114+
echo "$build_output" > "$LOG_DIR/backend-build-error.txt"
115+
if [ -n "$old_pid" ]; then
116+
kill_tree "$old_pid" 2>/dev/null || true
117+
while kill -0 "$old_pid" 2>/dev/null; do sleep 0.1; done
118+
fi
119+
./bin/errserver --port "$BACKEND_PORT" --msg-file "$LOG_DIR/backend-build-error.txt" >>"$LOG_DIR/backend.log" 2>&1 &
120+
echo $! > "$PID_DIR/backend.pid"
112121
fi
113122
done
114123
) >>"$LOG_DIR/backend.log" 2>&1 &

0 commit comments

Comments
 (0)