plandex-ai/plandex · error

Error marshalling response:

Error message

Error marshalling response: 

What it means

GetContextBodyHandler json.Marshal's shared.GetContextBodyResponse{Body: string}. Marshaling a struct with a plain string body cannot fail under normal conditions; an error here indicates an unexpected model change (unsupported field type, cycle) and yields HTTP 500 'Error marshalling response: <err>'.

Source

Thrown at app/server/handlers/plans_context.go:147

		if dbContext.Id == contextId {
			targetContext = dbContext
			break
		}
	}

	if targetContext == nil {
		http.Error(w, "Context not found", http.StatusNotFound)
		return
	}

	response := shared.GetContextBodyResponse{
		Body: targetContext.Body,
	}

	bytes, err := json.Marshal(response)
	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)
}

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

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

	vars := mux.Vars(r)
	planId := vars["planId"]
	branchName := vars["branch"]
	log.Println("planId: ", planId)

View on GitHub (pinned to e2d772072e)

Solutions

  1. Read err.Error() to find the unsupported type/field
  2. Audit recent changes to shared.GetContextBodyResponse
  3. Tag unserializable fields with json:"-" or implement MarshalJSON
  4. Deploy a known-good build to confirm the cause

Example fix

// before
type GetContextBodyResponse struct {
	Body string
	Meta map[string]any // may contain unsupported values
}
// after
type GetContextBodyResponse struct {
	Body string
	Meta map[string]any `json:"-"`
}
Defensive patterns

Strategy: type-guard

Validate before calling

func marshalable(v any) bool { _, err := json.Marshal(v); return err == nil }

Type guard

func isResponseBodySafe(resp shared.GetContextBodyResponse) bool {
	// Body must be a plain string and no extra unserializable fields added
	return true
}

Try / catch

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

Prevention

When it happens

Trigger: json.Marshal(response) errors because GetContextBodyResponse gained a field json cannot encode (func/chan/cyclic) after a code change.

Common situations: Custom builds or upgrades where shared.GetContextBodyResponse was extended with an unserializable field.

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/06a8c1273a9c0a87. Report an issue: GitHub.