gitbutlerapp/gitbutler · error

When using LM Studio, you must provide a valid endpoint

Error message

When using LM Studio, you must provide a valid endpoint

What it means

Thrown by the hunk-discard path when wt_change.unified_patch_with_filter(...) does not return UnifiedPatch::Patch. The enum also has Binary and TooLarge variants, so this fires when the worktree change is a binary change or the blob exceeds the size limit - there are no text hunks to subtract from, which the hunk algorithm requires.

Source

Thrown at apps/desktop/src/lib/ai/service.ts:331

			if (!get(this.tokenMemoryService.token)) {
				throw new Error("When using GitButler's API to summarize code, you must be logged in");
			}

			return new ButlerAIClient(this.cloud, modelKind);
		}

		if (modelKind === ModelKind.Ollama) {
			const ollamaEndpoint = await this.getOllamaEndpoint();
			const ollamaModelName = await this.getOllamaModelName();
			return new OllamaClient(ollamaEndpoint, ollamaModelName);
		}

		if (modelKind === ModelKind.LMStudio) {
			const lmStudioEndpoint = await this.getLMStudioEndpoint();
			const lmStudioModelName = await this.getLMStudioModelName();

			if (!lmStudioEndpoint) {
				throw new Error("When using LM Studio, you must provide a valid endpoint");
			}

			return new LMStudioClient(lmStudioEndpoint, lmStudioModelName);
		}

		if (modelKind === ModelKind.OpenAI) {
			const openAIModelName = await this.getOpenAIModelName();
			const openAIKey = await this.getOpenAIKey();
			const openAICustomEndpoint = await this.getOpenAICustomEndpoint();

			if (!openAIKey) {
				throw new Error(
					"When using OpenAI in a bring your own key configuration, you must provide a valid token",
				);
			}

			return new OpenAIClient(openAIKey, openAIModelName, openAICustomEndpoint);
		}

View on GitHub (pinned to caf1f223d3)

Solutions

  1. Use whole-file discard for that path: send the DiffSpec with empty hunk_headers
  2. Verify with git diff --binary / file(1) that the content is actually binary or oversized; if it is a misdetected text file, check .gitattributes filters or encoding (e.g. UTF-16 looks binary)
  3. Re-run the discard after refreshing worktree changes to rule out a race with a concurrent writer
  4. For legitimately large text files, whole-file mode is the only supported path

Example fix

// before
let specs = vec![DiffSpec { path, previous_path: None, hunk_headers: selected_hunks }];

// after
let specs = vec![DiffSpec { path, previous_path: None, hunk_headers: Vec::new() }];
Defensive patterns

Strategy: validation

Validate before calling

let wt = but_core::diff::worktree_changes(repo)?;
for spec in &changes {
    if spec.hunk_headers.is_empty() { continue; }
    if let Some(change) = wt.changes.iter().find(|c| c.path == spec.path) {
        match change.unified_patch(repo, 3)? {
            but_core::UnifiedPatch::Patch { .. } => {}
            _ => panic!("{} is binary/too-large: use whole-file discard", spec.path),
        }
    }
}

Type guard

fn has_text_hunks(patch: &but_core::UnifiedPatch) -> bool {
    matches!(patch, but_core::UnifiedPatch::Patch { .. })
}

Try / catch

if let Err(err) = discard_workspace_changes(repo, specs, ctx) {
    if err.to_string().contains("Couldn't obtain diff") {
        // retry offending path with empty hunk_headers (whole-file restore)
    } else { return Err(err); }
}

Prevention

When it happens

Trigger: Calling discard_workspace_changes with hunk_headers for a path whose current or previous content is binary (image, wasm, compiled artifact, or a file detected binary by the gix pipeline), or a file larger than the internal limit; occasionally also a race where the change vanished and the diff yields no patch.

Common situations: A file that used to be text replaced by binary content (or vice versa), build artifacts committed accidentally, large datasets/minified bundles exceeding the diff limit, or the file being touched by another process between status and discard.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20). Data as JSON: /api/errors/18373c13c4aa2845. Report an issue: GitHub.