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

Commit 258eb37

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 258eb37

3 files changed

Lines changed: 56 additions & 8 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+
}

docs/claude-progress.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Claude Progress Log
22
# Newest entries first. Agents: append your entry at the top after the header.
33

4+
---
5+
## 2026-05-18 | Session: Error server and JSON error responses
6+
Worked on: Errserver for failed Go compilation, JSON error responses for backend
7+
Completed:
8+
- Error server (backend/cmd/errserver): on Go build failure, the file watcher starts errserver which returns HTTP 500 with compilation error as JSON {"message": "..."}
9+
- OCP console's appFetch parses json.message automatically, so the UI shows actual compiler output instead of generic "Internal Server Error"
10+
Left off: Branch improve-test-cluster, PR #25 open. Backend JSON error response not yet pushed.
11+
Blockers: None
12+
413
---
514
## 2026-05-15 | Session: Better testing server setup (init.sh)
615
Worked on: Improve init.sh with PID files, port randomization, Go auto-recompile, agent docs
@@ -15,7 +24,7 @@ Completed:
1524
- Agent docs (AGENTS.md, WORKFLOW.md, init-session) reference .dev-env.json and .dev-logs/
1625
- Design spec and implementation plan written
1726
- 13 suites, 112 tests, all passing
18-
Left off: Branch improve-test-cluster, ready to push. Feature not yet marked as passes:true (needs manual testing confirmation).
27+
Left off: Branch improve-test-cluster, PR #25 open.
1928
Blockers: None
2029

2130
---

init.sh

Lines changed: 16 additions & 7 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,20 +97,28 @@ 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)
101-
if [ -n "$old_pid" ]; then
102-
kill "$old_pid" 2>/dev/null || true
103-
while kill -0 "$old_pid" 2>/dev/null; do sleep 0.1; done
104-
fi
100+
old_pid=$(cat "$PID_DIR/backend.pid" 2>/dev/null || true)
101+
build_output=$(cd backend && go build -buildvcs=false -o ../bin/backend-tmp . 2>&1) && build_ok=true || build_ok=false
102+
103+
if [ -n "$old_pid" ]; then
104+
kill_tree "$old_pid" 2>/dev/null || true
105+
while kill -0 "$old_pid" 2>/dev/null; do sleep 0.1; done
106+
fi
107+
108+
if $build_ok; then
105109
mv bin/backend-tmp bin/backend
106110
./bin/backend --http-port "$BACKEND_PORT" >>"$LOG_DIR/backend.log" 2>&1 &
107111
echo $! > "$PID_DIR/backend.pid"
108112
echo "[watcher] Backend restarted (PID $!)."
109113
else
110-
echo "[watcher] Build failed. Keeping current backend running."
114+
echo "[watcher] Build failed. Starting error server."
115+
echo "$build_output"
111116
rm -f bin/backend-tmp
117+
echo "$build_output" > "$LOG_DIR/backend-build-error.txt"
118+
./bin/errserver --port "$BACKEND_PORT" --msg-file "$LOG_DIR/backend-build-error.txt" >>"$LOG_DIR/backend.log" 2>&1 &
119+
echo $! > "$PID_DIR/backend.pid"
112120
fi
121+
113122
done
114123
) >>"$LOG_DIR/backend.log" 2>&1 &
115124
echo $! > "$PID_DIR/backend-watcher.pid"

0 commit comments

Comments
 (0)