vitessio/vitess · error
can't get %v: %v
Error message
can't get %v: %v
What it means
The vtgate HTTP debug API's handleCollection wraps any error from the per-collection getFunc into `can't get <collection>: <err>`. The collection name (e.g. tablets, keyspaces) is preserved so you know which REST resource failed. The wrapped inner error carries the actual cause.
Source
Thrown at go/vt/vtgate/api.go:62
func handleAPI(apiPath string, handlerFunc func(w http.ResponseWriter, r *http.Request) error) {
servenv.HTTPHandleFunc(apiPrefix+apiPath, func(w http.ResponseWriter, r *http.Request) {
defer func() {
if x := recover(); x != nil {
httpErrorf(w, r, "uncaught panic: %v", x)
}
}()
if err := handlerFunc(w, r); err != nil {
httpErrorf(w, r, "%v", err)
}
})
}
func handleCollection(collection string, getFunc func(*http.Request) (any, error)) {
handleAPI(collection+"/", func(w http.ResponseWriter, r *http.Request) error {
// Get the requested object.
obj, err := getFunc(r)
if err != nil {
return fmt.Errorf("can't get %v: %v", collection, err)
}
// JSON encode response.
data, err := json.MarshalIndent(obj, "", " ")
if err != nil {
return fmt.Errorf("cannot marshal data: %v", err)
}
w.Header().Set("Content-Type", jsonContentType)
w.Write(data)
return nil
})
}
func getItemPath(url string) string {
// Strip API prefix.
if !strings.HasPrefix(url, apiPrefix) {
return ""
}View on GitHub (pinned to 01a25a7d17)
Solutions
- Read the wrapped inner error for the real cause and fix that (bad name, missing object).
- Verify the collection path parameter (cell/keyspace/tablet) is correct.
- Check topology connectivity if the underlying error indicates topo failure.
Example fix
// before curl http://vtgate:15001/api/keyspaces/wrongks/ // after curl http://vtgate:15001/api/keyspaces/commerce/
Defensive patterns
Strategy: try-catch
Try / catch
resp, err := http.Get(base + "/api/keyspaces/" + ks + "/")
if err != nil || resp.StatusCode != 200 {
body, _ := io.ReadAll(resp.Body)
// body contains: can't get <collection>: <inner err>
log.Warn("vtgate API get failed", "body", string(body))
} Prevention
- Validate keyspace/cell names via vtctldclient before calling the HTTP API.
- Check the wrapped inner error — it names the real cause.
- Handle non-200 responses in scripts hitting the debug API.
When it happens
Trigger: Requesting a vtgate debug HTTP endpoint like /api/<collection>/ where getFunc fails — e.g. querying /api/tablets/ with a bad tablet filter or an unknown keyspace/cell, causing the underlying lookup to error.
Common situations: Scripts/curl against the vtgate debug API with mistyped collection values or keyspace/cell names; topology temporarily unreachable causing underlying getFunc errors.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- cannot marshal data: %v
- invalid health-check path: %q expected path: / or /cell/<ce
- err.Error() (template execute failure)
- err.Error() (Fprintf write failure)
- cells can only be listed, not retrieved
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/4e8d6f81debcd872.
Report an issue: GitHub.