xai-org/grok-build · error · anyhow::Error
either worktreePath or idOrPath must be set
Error message
either worktreePath or idOrPath must be set
What it means
remove_worktree needs a way to identify the target worktree, and this error is thrown when the request identifies none: both worktree_path and id_or_path are None. It is the complement of the both-set error and enforces that every removal request names exactly one target.
Source
Thrown at crates/codegen/xai-grok-workspace/src/worktree/mod.rs:1336
// ============================================================================
// Remove Worktree
// ============================================================================
pub async fn remove_worktree(
req: &RemoveWorktreeRequest,
copy_context: &BackgroundCopyContext,
) -> Result<RemoveWorktreeResponse> {
let resolved = match (&req.worktree_path, &req.id_or_path) {
(Some(_), Some(_)) => {
anyhow::bail!("exactly one of worktreePath or idOrPath must be set, not both")
}
(Some(path), None) => path.clone(),
(None, Some(id)) => match resolve_worktree_by_id_or_path(id)? {
Some(p) => p.display().to_string(),
None => anyhow::bail!("worktree not found: {id}"),
},
(None, None) => anyhow::bail!("either worktreePath or idOrPath must be set"),
};
let worktree_path = Path::new(&resolved);
tracing::info!(
target: WORKTREE_LOG,
path = %resolved,
force = req.force,
dry_run = req.dry_run,
"REMOVE_START: removing worktree"
);
// jj workspace: detect by .jj/repo and route to jj-specific cleanup.
if worktree_path.join(".jj").join("repo").exists() {
if req.dry_run {
return Ok(RemoveWorktreeResponse {
removed: false,
resolved_path: Some(resolved),
});View on GitHub (pinned to bc7f02eddd)
Solutions
- Populate either worktree_path or id_or_path before calling remove_worktree
- Validate the request before sending: error early if both fields are None
- Check that your JSON/serialization layer is not discarding the field (empty string vs null vs missing)
- Log the constructed RemoveWorktreeRequest at debug level to confirm which field you intended to set
Example fix
// before
let req = RemoveWorktreeRequest::default(); // both None
// after
let req = RemoveWorktreeRequest { id_or_path: Some(id), ..Default::default() }; Defensive patterns
Strategy: validation
Validate before calling
anyhow::ensure!(
req.worktree_path.is_some() || req.id_or_path.is_some(),
"remove_worktree requires worktree_path or id_or_path"
); Type guard
fn has_target(req: &RemoveWorktreeRequest) -> bool {
req.worktree_path.is_some() || req.id_or_path.is_some()
} Prevention
- Use a constructor like RemoveWorktreeRequest::by_id(id) / ::by_path(path) so an identifier is mandatory
- Avoid RemoveWorktreeRequest::default() as a starting point for removals
- When deserializing from JSON, reject payloads where both identifier fields are absent
When it happens
Trigger: Calling remove_worktree with a RemoveWorktreeRequest where both optional fields are left unset — e.g. constructing the struct with all defaults, forgetting to fill the chosen field, or a deserializer dropping empty/missing fields.
Common situations: Programmatic request building where the intended field was never assigned; JSON payloads where empty strings were coerced to None; copy-pasted request templates with identifiers removed for sanitization.
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.
Related errors
- exactly one of worktreePath or idOrPath must be set, not bot
- invalid deny glob {glob:?}: {e}
- hook JSON alias validation failed: {e}
- Invalid viewport height: {} (terminal height: {})
- no target specified
AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31).
Data as JSON: /api/errors/1d37714230fe2fd3.
Report an issue: GitHub.