{"record":{"id":"a5a7ca2989f74bd1","repo":"geektutu/7days-golang","slug":"err-error-a5a7ca","errorCode":null,"errorMessage":"err.Error()","messagePattern":"err\\.Error\\(\\)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"gee-cache/day6-single-flight/main.go","lineNumber":50,"sourceCode":"\t\t\treturn nil, fmt.Errorf(\"%s not exist\", key)\n\t\t}))\n}\n\nfunc startCacheServer(addr string, addrs []string, gee *geecache.Group) {\n\tpeers := geecache.NewHTTPPool(addr)\n\tpeers.Set(addrs...)\n\tgee.RegisterPeers(peers)\n\tlog.Println(\"geecache is running at\", addr)\n\tlog.Fatal(http.ListenAndServe(addr[7:], peers))\n}\n\nfunc startAPIServer(apiAddr string, gee *geecache.Group) {\n\thttp.Handle(\"/api\", http.HandlerFunc(\n\t\tfunc(w http.ResponseWriter, r *http.Request) {\n\t\t\tkey := r.URL.Query().Get(\"key\")\n\t\t\tview, err := gee.Get(key)\n\t\t\tif err != nil {\n\t\t\t\thttp.Error(w, err.Error(), http.StatusInternalServerError)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tw.Header().Set(\"Content-Type\", \"application/octet-stream\")\n\t\t\tw.Write(view.ByteSlice())\n\n\t\t}))\n\tlog.Println(\"fontend server is running at\", apiAddr)\n\tlog.Fatal(http.ListenAndServe(apiAddr[7:], nil))\n\n}\n\nfunc main() {\n\tvar port int\n\tvar api bool\n\tflag.IntVar(&port, \"port\", 8001, \"Geecache server port\")\n\tflag.BoolVar(&api, \"api\", false, \"Start a api server?\")\n\tflag.Parse()\n","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/geektutu/7days-golang/blob/cf3644382101dc13e7fd92e8f5c66cabc51bcd3b/gee-cache/day6-single-flight/main.go#L32-L68","documentation":"Generic 500 handler in the API server of the demo main: any error from gee.Get(key) (typically \"<key> not exist\" from the configured getter) is returned verbatim as the HTTP response. It fires for any cache retrieval failure on /api.","triggerScenarios":"Thrown at gee-cache/day6-single-flight/main.go:50 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the response body to identify the underlying cache error (e.g. \"<key> not exist\").","Pre-check key existence or map not-found to a 404 on the client side.","Add logging in the API handler to record the full error before returning it."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"cf3644382101dc13e7fd92e8f5c66cabc51bcd3b","analyzedAt":"2026-09-03T18:31:24.087Z","contentChangedAt":"2026-09-03T18:31:24.087Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}