plandex-ai/plandex · error

Error marshalling response:

Error message

Error marshalling response: 

What it means

After a successful create, the handler marshals the CreateProjectResponse (an {"id": ...} struct) with encoding/json. json.Marshal of a plain string field essentially cannot fail in practice; if it does, the handler returns 500 with the marshal error text.

Source

Thrown at app/server/handlers/projects.go:75

		return nil
	})

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

	resp := shared.CreateProjectResponse{
		Id: projectId,
	}

	bytes, err := json.Marshal(resp)

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

	w.Write(bytes)

	log.Println("Successfully created project", projectId)
}

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

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

	rows, err := db.Conn.Query("SELECT id, name FROM projects WHERE org_id = $1", auth.OrgId)

View on GitHub (pinned to e2d772072e)

Solutions

  1. Read the appended err.Error() in the log/response to see which field failed to marshal.
  2. Inspect shared.CreateProjectResponse for recently added fields with unsupported types (chan, func, sync values, cycles).
  3. Fix the response struct (use a supported type or add MarshalJSON) and rebuild the server.
  4. Add a unit test marshalling the response type to catch regressions.
Defensive patterns

Strategy: try-catch

Try / catch

body, err := io.ReadAll(res.Body)
if err != nil {
	return err
}
if res.StatusCode != http.StatusOK {
	return fmt.Errorf("create project failed: %s", string(body))
}

Prevention

When it happens

Trigger: Practically unreachable: would require resp to contain a value json.Marshal cannot encode. CreateProjectResponse holds only an Id string, so this branch is defensive dead code.

Common situations: You should essentially never hit this; seeing it implies the shared.CreateProjectResponse type was modified to include unsupported types such as channels, funcs, or cyclic pointers.

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/33aca7a2a9c948f8. Report an issue: GitHub.