plandex-ai/plandex · error

Error marshalling branches:

Error message

Error marshalling branches: 

What it means

A 500 returned when json.Marshal fails on the map[string]*shared.Branch result before writing the response. Practically this is rare — it only fails if Branch.ToApi() produced a value json cannot encode (e.g. an unsupported type like a channel, func, or a cyclic structure).

Source

Thrown at app/server/handlers/plans_crud.go:651

	var branches []db.Branch
	err = db.Conn.Select(&branches, query, queryArgs...)

	if err != nil {
		log.Printf("Error getting branches: %v\n", err)
		http.Error(w, "Error getting branches: "+err.Error(), http.StatusInternalServerError)
		return
	}

	res := map[string]*shared.Branch{}
	for _, branch := range branches {
		res[branch.PlanId] = branch.ToApi()
	}

	bytes, err := json.Marshal(res)

	if err != nil {
		log.Printf("Error marshalling branches: %v\n", err)
		http.Error(w, "Error marshalling branches: "+err.Error(), http.StatusInternalServerError)
		return
	}

	log.Println("Successfully processed GetCurrentBranchByPlanIdHandler request")

	w.Write(bytes)
}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Read the logged '%v' detail to identify the offending field/type
  2. Ensure all fields on shared.Branch are JSON-serializable (no channels, funcs, or cycles)
  3. If a custom MarshalJSON was added to Branch, fix or remove it
  4. Retry the request — transient corruption of in-memory state clears on restart
Defensive patterns

Strategy: try-catch

Try / catch

try {
  const res = await api.getCurrentBranchByPlanId(projectId, body);
} catch (err) {
  if (err.status === 500 && String(err.message).startsWith('Error marshalling branches:')) {
    // server-side serialization bug: report with server log detail
    console.error('Response serialization failed on server; likely version mismatch', err.message);
    return null;
  }
  throw err;
}

Prevention

When it happens

Trigger: A shared.Branch field of unmarshallable type (channel/func/cycle) introduced by a code change or corrupt DB row feeding ToApi().

Common situations: Custom builds with modified Branch/ToApi types; a plugin or fork adding non-serializable fields; corrupted rows producing unexpected values in custom field types with broken MarshalJSON.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/3baf6e56374258fe. Report an issue: GitHub.