{"record":{"id":"2896028e498643ca","repo":"AlexxIT/go2rtc","slug":"code-must-be-in-the-range-0-125","errorCode":null,"errorMessage":"Code must be in the range [0, 125]","messagePattern":"Code must be in the range \\[0, 125\\]","errorType":"http","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"internal/api/api.go","lineNumber":257,"sourceCode":"\tmu.Lock()\n\tapp.Info[\"host\"] = r.Host\n\tmu.Unlock()\n\n\tResponseJSON(w, app.Info)\n}\n\nfunc exitHandler(w http.ResponseWriter, r *http.Request) {\n\tif r.Method != \"POST\" {\n\t\thttp.Error(w, \"\", http.StatusBadRequest)\n\t\treturn\n\t}\n\n\ts := r.URL.Query().Get(\"code\")\n\tcode, err := strconv.Atoi(s)\n\n\t// https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_08_02\n\tif err != nil || code < 0 || code > 125 {\n\t\thttp.Error(w, \"Code must be in the range [0, 125]\", http.StatusBadRequest)\n\t\treturn\n\t}\n\n\tos.Exit(code)\n}\n\nfunc restartHandler(w http.ResponseWriter, r *http.Request) {\n\tif r.Method != \"POST\" {\n\t\thttp.Error(w, \"\", http.StatusBadRequest)\n\t\treturn\n\t}\n\n\tpath, err := os.Executable()\n\tif err != nil {\n\t\thttp.Error(w, err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/internal/api/api.go#L239-L275","documentation":"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).","triggerScenarios":"GET /api/exit without a code, with code=abc, code=999, code=-1, or any value > 125.","commonSituations":"Scripts passing shell exit codes above 125 (e.g. 128+signal convention), typos in the query string, omitting the parameter entirely.","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"],"exampleFix":"// before\ncurl -X POST \"http://host:1984/api/exit?code=130\"\n// after\ncurl -X POST \"http://host:1984/api/exit?code=1\"","handlingStrategy":"validation","validationCode":"const code = Number(query.get('code'));\nif (!Number.isInteger(code) || code < 0 || code > 125) {\n  throw new Error('exit code must be an integer in [0,125]');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp/validate exit codes to 0-125 before calling /api/exit","Avoid 128+signal conventions with this endpoint","URL-encode the query string"],"tags":["http","api","validation","exit-code"],"backgroundTag":"value-out-of-range","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}