plandex-ai/plandex · error

error getting current plan state: %v

Error message

error getting current plan state: %v

What it means

GetPlanDiffs starts by calling GetCurrentPlanState to assemble the plan's current file state, and wraps any failure as this error. Without the plan state, diffs cannot be computed, so the function aborts before creating its temp directory.

Source

Thrown at app/server/db/diff_helpers.go:22

	"fmt"
	"log"
	"os"
	"os/exec"
	"path/filepath"
	"runtime"
	"runtime/debug"

	shared "plandex-shared"
)

func GetPlanDiffs(orgId, planId string, plain bool) (string, error) {
	planState, err := GetCurrentPlanState(CurrentPlanStateParams{
		OrgId:  orgId,
		PlanId: planId,
	})

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

	// create temp directory
	tempDirPath, err := os.MkdirTemp(getOrgDir(orgId), "tmp-diffs-*")

	if err != nil {
		return "", fmt.Errorf("error creating temp dir: %v", err)
	}

	defer func() {
		go os.RemoveAll(tempDirPath)
	}()

	// init a git repo in the temp dir
	err = initGitRepo(tempDirPath)

	if err != nil {
		return "", fmt.Errorf("error initializing git repo: %v", err)

View on GitHub (pinned to e2d772072e)

Solutions

  1. Check the wrapped %v error to see whether it was a DB error or a missing-plan error
  2. Verify orgId and planId refer to an existing plan visible to the caller
  3. Run migrations and confirm plan/file state tables are intact
  4. Add a pre-check (plan exists) before computing diffs for better error messages

Example fix

// before
planState, err := GetCurrentPlanState(CurrentPlanStateParams{OrgId: orgId, PlanId: planId})
if err != nil { return "", fmt.Errorf("error getting current plan state: %v", err) }
// after
if exists, err := PlanExists(orgId, planId); err != nil || !exists {
    return "", fmt.Errorf("plan %s not found for org %s", planId, orgId)
}
planState, err := GetCurrentPlanState(CurrentPlanStateParams{OrgId: orgId, PlanId: planId})
Defensive patterns

Strategy: validation

Validate before calling

if orgId == "" || planId == "" {
    return errors.New("orgId and planId are required for plan diffs")
}
exists, err := planExists(orgId, planId)
if err != nil || !exists {
    return fmt.Errorf("plan %s not found for org %s", planId, orgId)
}

Try / catch

diff, err := db.GetPlanDiffs(orgId, planId, files)
if err != nil && strings.Contains(err.Error(), "error getting current plan state") {
    log.Printf("plan state unavailable: %v", err)
    return fmt.Errorf("cannot diff plan %s: verify it exists and is accessible", planId)
}

Prevention

When it happens

Trigger: An anonymous caller invokes GetPlanDiffs while GetCurrentPlanState fails: nonexistent planId/orgId, DB query error, or corrupted/missing plan files referenced by the state.

Common situations: Requesting diffs for a deleted or not-yet-created plan; cross-org access where the plan belongs to another org; database connectivity issues mid-request.

Related errors


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