{"record":{"id":"1d37714230fe2fd3","repo":"xai-org/grok-build","slug":"either-worktreepath-or-idorpath-must-be-set","errorCode":null,"errorMessage":"either worktreePath or idOrPath must be set","messagePattern":"either worktreePath or idOrPath must be set","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-workspace/src/worktree/mod.rs","lineNumber":1336,"sourceCode":"\n// ============================================================================\n// Remove Worktree\n// ============================================================================\n\npub async fn remove_worktree(\n    req: &RemoveWorktreeRequest,\n    copy_context: &BackgroundCopyContext,\n) -> Result<RemoveWorktreeResponse> {\n    let resolved = match (&req.worktree_path, &req.id_or_path) {\n        (Some(_), Some(_)) => {\n            anyhow::bail!(\"exactly one of worktreePath or idOrPath must be set, not both\")\n        }\n        (Some(path), None) => path.clone(),\n        (None, Some(id)) => match resolve_worktree_by_id_or_path(id)? {\n            Some(p) => p.display().to_string(),\n            None => anyhow::bail!(\"worktree not found: {id}\"),\n        },\n        (None, None) => anyhow::bail!(\"either worktreePath or idOrPath must be set\"),\n    };\n    let worktree_path = Path::new(&resolved);\n\n    tracing::info!(\n        target: WORKTREE_LOG,\n        path = %resolved,\n        force = req.force,\n        dry_run = req.dry_run,\n        \"REMOVE_START: removing worktree\"\n    );\n\n    // jj workspace: detect by .jj/repo and route to jj-specific cleanup.\n    if worktree_path.join(\".jj\").join(\"repo\").exists() {\n        if req.dry_run {\n            return Ok(RemoveWorktreeResponse {\n                removed: false,\n                resolved_path: Some(resolved),\n            });","sourceCodeStart":1318,"sourceCodeEnd":1354,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-workspace/src/worktree/mod.rs#L1318-L1354","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nlet req = RemoveWorktreeRequest::default(); // both None\n// after\nlet req = RemoveWorktreeRequest { id_or_path: Some(id), ..Default::default() };","handlingStrategy":"validation","validationCode":"anyhow::ensure!(\n    req.worktree_path.is_some() || req.id_or_path.is_some(),\n    \"remove_worktree requires worktree_path or id_or_path\"\n);","typeGuard":"fn has_target(req: &RemoveWorktreeRequest) -> bool {\n    req.worktree_path.is_some() || req.id_or_path.is_some()\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["validation","missing-argument","rust"],"backgroundTag":"missing-required-parameter","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}