plandex-ai/plandex · error

err.Error()

Error message

err.Error()

What it means

When rendering diffs as an HTML page in the local web server started by the CLI, template execution (tmpl.Execute) can fail. The handler writes err.Error() to the HTTP response with status 500, so the browser shows the raw Go template error text. It means the template and the data passed to it are incompatible (bad field references, wrong types).

Source

Thrown at app/cli/cmd/diffs.go:124

				term.OutputErrorAndExit("Error parsing template: %v", err)
			}

			// Use :0 to let the OS pick an available port
			listener, err := net.Listen("tcp", ":0")
			if err != nil {
				term.OutputErrorAndExit("Error starting server: %v", err)
			}

			// Get the actual port chosen
			port := listener.Addr().(*net.TCPAddr).Port

			// Start web server
			go func() {
				http.HandleFunc("/"+outputFormat, func(w http.ResponseWriter, r *http.Request) {
					w.Header().Set("Content-Type", "text/html; charset=utf-8")
					err := tmpl.Execute(w, data)
					if err != nil {
						http.Error(w, err.Error(), http.StatusInternalServerError)
					}
				})
				http.Serve(listener, nil)
			}()

			ui.OpenURL("Showing "+outputFormat+" diffs in your default browser...", fmt.Sprintf("http://localhost:%d/%s", port, outputFormat))

			fmt.Println()

			return listener
		}

		listener := getNewListener()
		defer listener.Close()

		var relaunch bool

		for {

View on GitHub (pinned to e2d772072e)

Solutions

  1. Read the error message shown in the browser — it names the exact template field or parse problem
  2. Update the CLI to the latest version so template and data struct are back in sync
  3. Re-run the command; if persistent, use a non-HTML output format (e.g. plain text diff) as a workaround
  4. Check port conflicts / stale server processes and restart so the handler is freshly registered

Example fix

// before
err := tmpl.Execute(w, data)
if err != nil {
    http.Error(w, err.Error(), http.StatusInternalServerError)
}
// after
err := tmpl.Execute(w, data)
if err != nil {
    log.Printf("template execute failed: %v", err)
    http.Error(w, "failed to render diffs", http.StatusInternalServerError)
}
Defensive patterns

Strategy: try-catch

Try / catch

if err := tmpl.Execute(w, data); err != nil {
    log.Printf("template error: %v", err)
    http.Error(w, "failed to render diffs", http.StatusInternalServerError)
}

Prevention

When it happens

Trigger: Running `diffs` with an HTML output format; the diff data struct passed to the template lacks a field the template references, or the template file itself has invalid syntax, causing tmpl.Execute to return an error at request time.

Common situations: Upgrading the CLI where the embedded template and data struct drifted out of sync; viewing very large diffs that time out or get truncated mid-template; malformed template assets on a customized install.

Related errors


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