plandex-ai/plandex · error

Error marshalling response

Error message

Error marshalling response

What it means

json.Marshal(shared.GetPlanConfigResponse) failed, returning HTTP 500. Since Go's encoding/json only errors on unsupported values (chan, func, complex, cyclic data), this points to a defect in the response struct or a custom marshaler, not client input.

Source

Thrown at app/server/handlers/plan_config.go:48

	if plan == nil {
		return
	}

	config, err := db.GetPlanConfig(planId)
	if err != nil {
		log.Println("Error getting plan config: ", err)
		http.Error(w, "Error getting plan config", http.StatusInternalServerError)
		return
	}

	res := shared.GetPlanConfigResponse{
		Config: config,
	}

	bytes, err := json.Marshal(res)
	if err != nil {
		log.Println("Error marshalling response: ", err)
		http.Error(w, "Error marshalling response", http.StatusInternalServerError)
		return
	}

	w.Write(bytes)
	log.Println("GetPlanConfigHandler processed successfully")
}

func UpdatePlanConfigHandler(w http.ResponseWriter, r *http.Request) {
	log.Println("Received request for UpdatePlanConfigHandler")

	auth := Authenticate(w, r, true)
	if auth == nil {
		return
	}

	vars := mux.Vars(r)
	planId := vars["planId"]

View on GitHub (pinned to e2d772072e)

Solutions

  1. Read the logged marshal error to identify the offending field
  2. Audit GetPlanConfigResponse and the PlanConfig model for unsupported field types
  3. Add a regression test marshaling a fully populated GetPlanConfigResponse
  4. Ensure config values loaded from the DB are deserialized into API-safe types first
Defensive patterns

Strategy: fallback

Validate before calling

// server-side: CI test for the response shape
func TestGetPlanConfigResponseMarshal(t *testing.T) {
    _, err := json.Marshal(shared.GetPlanConfigResponse{Config: sampleConfig()})
    if err != nil { t.Fatal(err) }
}

Try / catch

bytes, err := json.Marshal(res)
if err != nil {
    log.Printf("Error marshalling response: %v", err)
    http.Error(w, "Error marshalling response", http.StatusInternalServerError)
    return
}

Prevention

When it happens

Trigger: The fetched plan config response struct contains an unserializable field (e.g. a channel or function), a field's MarshalJSON method errors, or a cyclic reference exists in nested config data.

Common situations: Newly added config field of unsupported type, accidentally embedding a DB model with a sqlx-specific unserializable type, custom MarshalJSON returning an error on odd stored values.

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 plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/290b1847689c6e17. Report an issue: GitHub.