vitessio/vitess · error

err.Error() (JSON marshal failure)

Error message

err.Error() (JSON marshal failure)

What it means

When /livequeryz?format=json is requested, the handler marshals the live-query rows to JSON and returns HTTP 500 with the marshal error text if json.Marshal fails. In practice this is rare — it indicates rows contain data JSON cannot encode (e.g. unsupported types surfacing via custom marshaling).

Source

Thrown at go/vt/vttablet/tabletserver/livequeryz.go:75

func livequeryzHandler(queryLists []*QueryList, w http.ResponseWriter, r *http.Request) {
	if err := acl.CheckAccessHTTP(r, acl.DEBUGGING); err != nil {
		acl.SendError(w, err)
		return
	}
	var rows []QueryDetailzRow
	for _, ql := range queryLists {
		rows = ql.AppendQueryzRows(rows)
	}
	if err := r.ParseForm(); err != nil {
		http.Error(w, fmt.Sprintf("cannot parse form: %s", err), http.StatusInternalServerError)
		return
	}
	format := r.FormValue("format")
	if format == "json" {
		js, err := json.Marshal(rows)
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		w.Header().Set("Content-Type", "application/json")
		w.Write(js)
		return
	}
	logz.StartHTMLTable(w)
	defer logz.EndHTMLTable(w)
	w.Write(livequeryzHeader)
	for i := range rows {
		if err := livequeryzTmpl.Execute(w, rows[i]); err != nil {
			log.Error(fmt.Sprintf("livequeryz: couldn't execute template: %v", err))
		}
	}
}

func livequeryzTerminateHandler(queryLists []*QueryList, w http.ResponseWriter, r *http.Request) {
	if err := acl.CheckAccessHTTP(r, acl.ADMIN); err != nil {

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Check the marshaled error text in the 500 body for the offending field
  2. Retry without format=json to get the HTML rendering (which doesn't marshal to JSON)
  3. Report/pin the failing row data if reproducible — this usually indicates a code bug
Defensive patterns

Strategy: fallback

Try / catch

resp, err := http.Get(baseURL + "/livequeryz?format=json")
if resp != nil && resp.StatusCode != http.StatusOK {
    // fall back to the default HTML rendering
    resp2, err := http.Get(baseURL + "/livequeryz")
    _ = resp2
    _ = err
}

Prevention

When it happens

Trigger: GET /livequeryz?format=json while json.Marshal(rows) errors on the QueryDetailzRow slice.

Common situations: Corrupted or unexpected values in in-flight query metadata; custom marshaler bugs after code changes; practically almost never seen with stock row types.

Understand the failure class

Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/49f4ee24cca5d5b8. Report an issue: GitHub.