plandex-ai/plandex · error
Error marshalling branches:
Error message
Error marshalling branches:
What it means
ListBranchesHandler calls json.Marshal on the []*db.Branch slice and returns HTTP 500 'Error marshalling branches: <err>' if serialization fails. json.Marshal only errors on unsupported types (e.g. unexported fields with custom MarshalJSON returning an error, channels, funcs, or invalid UTF-8/cyclic data). In practice this is nearly always a bug in the Branch type's serialization, not in the request.
Source
Thrown at app/server/handlers/branches.go:71
return err
}
branches = res
return nil
})
if err != nil {
log.Printf("Error getting branches: %v\n", err)
http.Error(w, "Error getting branches: "+err.Error(), http.StatusInternalServerError)
return
}
jsonBytes, err := json.Marshal(branches)
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 retrieved branches")
w.Write(jsonBytes)
}
func CreateBranchHandler(w http.ResponseWriter, r *http.Request) {
log.Println("Received request for CreateBranchHandler")
auth := Authenticate(w, r, true)
if auth == nil {
return
}
vars := mux.Vars(r)
planId := vars["planId"]View on GitHub (pinned to e2d772072e)
Solutions
- Read the wrapped marshal error in the server log to identify the offending field
- Inspect db.Branch for recently added fields with custom MarshalJSON or unsupported types
- Fix the MarshalJSON implementation or mark the field with `json:"-"` to skip it
Example fix
// before
type Branch struct {
Meta chan string `json:"meta"` // unsupported type
}
// after
type Branch struct {
Meta chan string `json:"-"` // excluded from JSON
} Defensive patterns
Strategy: try-catch
Try / catch
// server-side: this is a serialization bug; log full error and fail fast in tests
testBranches := []*db.Branch{{...}}
if _, err := json.Marshal(testBranches); err != nil {
t.Fatalf("Branch type not JSON-serializable: %v", err)
} Prevention
- Add a serialization smoke test for db.Branch whenever its fields change
- Mark internal/non-serializable fields with `json:"-"`
- Avoid custom MarshalJSON implementations unless tested
- Keep db.Branch free of channels, funcs, and cyclic references
When it happens
Trigger: The branches slice retrieved from ListPlanBranches contains a field whose MarshalJSON fails or an unsupported type (channel/func/cyclic reference) added to db.Branch; extremely rare in normal operation.
Common situations: A developer recently added a field to db.Branch (e.g. a custom struct or time-like type) with a broken MarshalJSON implementation; embedding a non-serializable type after a schema change.
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
- Error marshalling response:
- Error marshalling invites:
- Error marshalling response
- Error marshalling contexts:
- Error marshalling response:
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/8ace9090b98ae025.
Report an issue: GitHub.