{"record":{"id":"0502f3507f734077","repo":"gocolly/colly","slug":"internal-server-error","errorCode":null,"errorMessage":"internal server error","messagePattern":"internal server error","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"debug/webdebugger.go","lineNumber":150,"sourceCode":"    }\n    setTimeout(fetchStatus, 1000);\n  });\n}\n$(document).ready(function() {\n    fetchStatus();\n});\n</script>\n</body>\n</html>\n`))\n}\n\nfunc (w *WebDebugger) statusHandler(wr http.ResponseWriter, r *http.Request) {\n\tw.Lock()\n\tjsonData, err := json.MarshalIndent(w, \"\", \"  \")\n\tw.Unlock()\n\tif err != nil {\n\t\thttp.Error(wr, \"internal server error\", http.StatusInternalServerError)\n\t\tlog.Println(\"Error marshaling status JSON:\", err)\n\t\treturn\n\t}\n\twr.Write(jsonData)\n}\n","sourceCodeStart":132,"sourceCodeEnd":156,"githubUrl":"https://github.com/gocolly/colly/blob/17d1d6ca92bd32a5651f34256bf7a2855c967f65/debug/webdebugger.go#L132-L156","documentation":"The WebDebugger's statusHandler marshals the WebDebugger state to JSON for its /status HTTP endpoint; if json.MarshalIndent fails it responds with 500 'internal server error' and logs the underlying marshal error. This means the debugger's internal state could not be serialized (e.g. an unmarshalable field such as a channel, func, or cyclic reference).","triggerScenarios":"GETting the web debugger's status endpoint while WebDebugger state contains values json.MarshalIndent cannot encode (channels, funcs, cyclic data), returning the literal 500 body 'internal server error'.","commonSituations":"Scraping the debugger status page programmatically and getting 500; running colly with debug/webdebugger enabled and checking status during or after complex scraping; custom modifications adding non-serializable fields to WebDebugger.","solutions":["Check the server log line 'Error marshaling status JSON:' for the underlying marshal error","Avoid creating/cyclic request state that breaks JSON marshaling of the debugger, or upgrade colly if a serialization bug was fixed","Serve status from a sanitized snapshot struct that excludes unserializable fields","If only scraping colly itself, treat HTTP 500 from the status endpoint as debugger-level failure and retry/backoff"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"resp, err := http.Get(debuggerStatusURL)\nif err != nil { return err }\nif resp.StatusCode == http.StatusInternalServerError {\n    return errors.New(\"debugger status endpoint failed to marshal state\")\n}","typeGuard":null,"tryCatchPattern":"func fetchStatus(url string) ([]byte, error) {\n    resp, err := http.Get(url)\n    if err != nil { return nil, err }\n    defer resp.Body.Close()\n    if resp.StatusCode != http.StatusOK {\n        return nil, fmt.Errorf(\"status endpoint returned %d\", resp.StatusCode)\n    }\n    return io.ReadAll(resp.Body)\n}","preventionTips":["Watch server logs for 'Error marshaling status JSON:' to find the unserializable field","Keep WebDebugger state free of channels/funcs/cyclic references if extending it","Serve status from a dedicated serializable snapshot struct instead of marshaling the live object","Treat 500 from the status endpoint as transient and retry with backoff"],"tags":["http","json","serialization","debugging"],"backgroundTag":"json-marshal-failed","analyzedSha":"17d1d6ca92bd32a5651f34256bf7a2855c967f65","analyzedAt":"2026-08-30T21:32:31.579Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}