plandex-ai/plandex · error

error getting current plan state params: %v

Error message

error getting current plan state params: %v

What it means

This error is returned by the ApplyPlanHandler in plans_changes.go when db.GetFullCurrentPlanStateParams(auth.OrgId, planId) fails while assembling the plan snapshot inside a read-locked ExecRepoOperation. It wraps the underlying DB error, so the root cause (query failure, missing org/plan rows, connection issue) is in the wrapped %v. The handler converts it into an HTTP 500 'Error getting current plan state'.

Source

Thrown at app/server/handlers/plans_changes.go:168

	err = db.ExecRepoOperation(db.ExecRepoOperationParams{
		OrgId:    auth.OrgId,
		UserId:   auth.User.Id,
		PlanId:   planId,
		Branch:   branch,
		Scope:    db.LockScopeRead,
		Ctx:      ctx,
		CancelFn: cancel,
	}, func(repo *db.GitRepo) error {
		var err error
		settings, err = db.GetPlanSettings(plan)
		if err != nil {
			return fmt.Errorf("error getting plan settings: %v", err)
		}

		currentPlanParams, err = db.GetFullCurrentPlanStateParams(auth.OrgId, planId)
		if err != nil {
			return fmt.Errorf("error getting current plan state params: %v", err)
		}

		currentPlan, err = db.GetCurrentPlanState(currentPlanParams)
		if err != nil {
			return fmt.Errorf("error getting current plan state: %v", err)
		}

		return nil
	})

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

	log.Println("ApplyPlanHandler: Got current plan state:", currentPlan != nil)

View on GitHub (pinned to e2d772072e)

Solutions

  1. Inspect the wrapped '%v' detail in the server log to find the root DB error
  2. Verify the Postgres/DB connection config and that the DB is reachable
  3. Confirm the planId exists for the authenticated org before calling apply
  4. Retry the request if the failure was a transient connection error

Example fix

// before
currentPlanParams, err = db.GetFullCurrentPlanStateParams(auth.OrgId, planId)
if err != nil {
    return fmt.Errorf("error getting current plan state params: %v", err)
}
// after
currentPlanParams, err = db.GetFullCurrentPlanStateParams(auth.OrgId, planId)
if err != nil {
    if planId == "" {
        return fmt.Errorf("error getting current plan state params: empty planId: %w", err)
    }
    return fmt.Errorf("error getting current plan state params for plan %s: %w", planId, err)
}
Defensive patterns

Strategy: validation

Validate before calling

if planId == "" {
    return errors.New("planId is required before fetching plan state params")
}
if err := db.PingContext(ctx); err != nil {
    return fmt.Errorf("database unreachable: %w", err)
}

Try / catch

err := db.ExecRepoOperation(params, func(repo *db.GitRepo) error {
    currentPlanParams, err = db.GetFullCurrentPlanStateParams(orgId, planId)
    if err != nil {
        return fmt.Errorf("error getting current plan state params: %w", err)
    }
    return nil
})
if err != nil {
    log.Printf("plan state params load failed: %v", err)
    http.Error(w, "plan state unavailable", http.StatusServiceUnavailable)
    return
}

Prevention

When it happens

Trigger: Calling the apply-plan endpoint when the org/plan lookup inside GetFullCurrentPlanStateParams fails: database unreachable, plan row missing/corrupt, or a SQL error while assembling current plan state params.

Common situations: DB container down or migrated mid-request; planId belonging to another org so the query returns an error; transient connection pool exhaustion under load.

Related errors


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