plandex-ai/plandex · error

error getting diffs: %v

Error message

error getting diffs: %v

What it means

Inside buildValidate, before sending content to the model for validation, the code computes a diff between the original and updated file via diff_pkg.GetDiffs(originalFile, updated). If this fails the error is wrapped as "error getting diffs: %v" and buildValidate returns immediately, failing the current validation attempt. It is a local diffing failure preceding any LLM call.

Source

Thrown at app/server/model/plan/build_validate_and_fix.go:209

	authVars := fileState.authVars
	modelConfig := params.modelConfig

	originalFile := params.originalFile
	updated := params.updated
	proposedContent := params.proposedContent
	desc := params.desc
	onStream := params.onStream
	syntaxErrors := params.syntaxErrors
	reasons := params.reasons

	baseModelConfig := modelConfig.GetBaseModelConfig(authVars, fileState.settings, fileState.orgUserConfig)

	// Get diff for validation
	log.Printf("Getting diffs between original and updated content")
	diff, err := diff_pkg.GetDiffs(originalFile, updated)
	if err != nil {
		log.Printf("Error getting diffs: %v", err)
		return buildValidateResult{}, fmt.Errorf("error getting diffs: %v", err)
	}

	originalWithLineNums := shared.AddLineNums(originalFile)
	proposedWithLineNums := shared.AddLineNums(proposedContent)

	maxExpectedOutputTokens := shared.GetNumTokensEstimate(originalFile)/2 + shared.GetNumTokensEstimate(proposedContent)

	// Choose prompt and tools based on preferred format

	log.Printf("Building XML validation replacements prompt")
	promptText, headNumTokens := prompts.GetValidationReplacementsXmlPrompt(prompts.ValidationPromptParams{
		Path:                 filePath,
		OriginalWithLineNums: originalWithLineNums,
		Desc:                 desc,
		ProposedWithLineNums: proposedWithLineNums,
		Diff:                 diff,
		SyntaxErrors:         syntaxErrors,
		Reasons:              reasons,

View on GitHub (pinned to e2d772072e)

Solutions

  1. Log/inspect the inner error and sanity-check both originalFile and updated (length, UTF-8 validity) before calling GetDiffs.
  2. Sanitize or truncate the updated content; reject obviously invalid LLM output earlier in the pipeline.
  3. Upgrade or patch the diff package if the error traces inside it.
  4. Fall back to a no-diff validation mode (send full files without line-numbered diff) when diffing fails.

Example fix

// before
diff, err := diff_pkg.GetDiffs(originalFile, updated)
if err != nil {
    return buildValidateResult{}, fmt.Errorf("error getting diffs: %v", err)
}
// after
if !utf8.ValidString(updated) || updated == "" {
    return buildValidateResult{}, fmt.Errorf("updated content invalid, skipping diff")
}
diff, err := diff_pkg.GetDiffs(originalFile, updated)
if err != nil {
    log.Printf("GetDiffs failed (%v); proceeding without diff context", err)
    diff = ""
}
Defensive patterns

Strategy: validation

Validate before calling

func diffable(original, updated string) error {
    if original == "" || updated == "" {
        return fmt.Errorf("empty content")
    }
    if !utf8.ValidString(original) || !utf8.ValidString(updated) {
        return fmt.Errorf("non-UTF-8 content")
    }
    if strings.ContainsRune(updated, 0) {
        return fmt.Errorf("null bytes in updated content")
    }
    return nil
}

Try / catch

diff, err := diff_pkg.GetDiffs(originalFile, updated)
if err != nil {
    log.Printf("GetDiffs failed: %v; continuing validation without diff", err)
    diff = ""
}

Prevention

When it happens

Trigger: diff_pkg.GetDiffs(originalFile, updated) returns a non-nil error — typically undiffable content (binary-looking or invalid-UTF-8 LLM output, empty/nil content, huge files) or an internal failure of the diff package.

Common situations: A previous repair step produced mangled output (null bytes, mixed encodings) that the differ cannot process; diff package version change; file so large the diff algorithm exceeds limits or times out.

Related errors


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