{"record":{"id":"3a0408e59c8737ba","repo":"AlexxIT/go2rtc","slug":"err-error","errorCode":null,"errorMessage":"err.Error()","messagePattern":"err\\.Error\\(\\)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"internal/api/api.go","lineNumber":272,"sourceCode":"\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\n\tlog.Debug().Msgf(\"[api] restart %s\", path)\n\n\tgo syscall.Exec(path, os.Args, os.Environ())\n}\n\nfunc logHandler(w http.ResponseWriter, r *http.Request) {\n\tswitch r.Method {\n\tcase \"GET\":\n\t\t// Send current state of the log file immediately\n\t\tw.Header().Set(\"Content-Type\", \"application/jsonlines\")\n\t\t_, _ = app.MemoryLog.WriteTo(w)\n\tcase \"DELETE\":\n\t\tapp.MemoryLog.Reset()\n\t\tResponse(w, \"OK\", \"text/plain\")\n\tdefault:","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/internal/api/api.go#L254-L290","documentation":"In restartHandler, if os.Executable() fails (it cannot determine the path of the running binary), the error text is returned verbatim as a 500 response. This is not a panic message but the propagated err.Error() string.","triggerScenarios":"Calling POST /api/restart when the executable path can't be resolved - e.g. the binary was deleted/replaced on disk while running, or running in an environment where /proc-style path resolution fails (deleted inode: 'os.Executable: ... no such file or directory').","commonSituations":"Container images where the binary was swapped/removed after start; upgraded binary deleted the old inode; unusual embedded environments.","solutions":["Ensure the go2rtc binary still exists at its original path, then retry POST /api/restart","Restart the container/service via the platform (docker restart, systemctl restart) instead of the API","If running from a deleted file, start go2rtc from a stable path before relying on API restart"],"exampleFix":"// before\n# binary replaced in place -> inode deleted\ncurl -X POST http://host:1984/api/restart\n// after\ndocker restart go2rtc   # or systemctl restart go2rtc, then verify binary exists before API restart","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"const res = await fetch(url, { method: 'POST' });\nif (!res.ok) {\n  const detail = await res.text();\n  throw new Error('restart failed (' + res.status + '): ' + detail);\n}","preventionTips":["Run go2rtc from a stable binary path so os.Executable() succeeds","Avoid replacing the binary in place while the process runs","Fall back to service-manager restart when the API returns 500"],"tags":["http","api","restart","os-executable"],"backgroundTag":"http-error-response","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"}