AlexxIT/go2rtc · warning
Code must be in the range [0, 125]
Error message
Code must be in the range [0, 125]
What it means
The /api/exit handler validates that the ?code= query parameter parses as an integer within 0-125 (POSIX exit-code convention). Values outside this range, non-numeric values, or a missing code produce a 400 with this message; otherwise the process calls os.Exit(code).
Solutions
- Pass a valid code: POST /api/exit?code=0 (range 0-125)
- Translate 128+signal style codes down to a value <=125 before calling the API
- Quote/encode the URL so the code parameter isn't dropped or mangled by the shell
Example fix
// before curl -X POST "http://host:1984/api/exit?code=130" // after curl -X POST "http://host:1984/api/exit?code=1"
Defensive patterns
Strategy: validation
Validate before calling
const code = Number(query.get('code'));
if (!Number.isInteger(code) || code < 0 || code > 125) {
throw new Error('exit code must be an integer in [0,125]');
} Prevention
- Clamp/validate exit codes to 0-125 before calling /api/exit
- Avoid 128+signal conventions with this endpoint
- URL-encode the query string
When it happens
Trigger: GET /api/exit without a code, with code=abc, code=999, code=-1, or any value > 125.
Common situations: Scripts passing shell exit codes above 125 (e.g. 128+signal convention), typos in the query string, omitting the parameter entirely.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07).
Data as JSON: /api/errors/2896028e498643ca.
Report an issue: GitHub.
Appendix: source
Thrown at internal/api/api.go:257
mu.Lock()
app.Info["host"] = r.Host
mu.Unlock()
ResponseJSON(w, app.Info)
}
func exitHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.Error(w, "", http.StatusBadRequest)
return
}
s := r.URL.Query().Get("code")
code, err := strconv.Atoi(s)
// https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_08_02
if err != nil || code < 0 || code > 125 {
http.Error(w, "Code must be in the range [0, 125]", http.StatusBadRequest)
return
}
os.Exit(code)
}
func restartHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.Error(w, "", http.StatusBadRequest)
return
}
path, err := os.Executable()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
View on GitHub (pinned to c245815e75)