{"record":{"id":"6e2376223d1ad0bb","repo":"gitbutlerapp/gitbutler","slug":"cannot-snapshot-a-null-target-commit-id","errorCode":null,"errorMessage":"cannot snapshot a null target commit id","messagePattern":"cannot snapshot a null target commit id","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-oplog/src/oplog.rs","lineNumber":77,"sourceCode":"    virtual_branches: VirtualBranches,\n}\n\n#[derive(serde::Deserialize)]\n#[serde(rename_all = \"camelCase\")]\nstruct SnapshotTarget {\n    branch_name: String,\n    remote_name: String,\n    sha: String,\n    push_remote_name: Option<String>,\n}\n\nimpl TryFrom<&ProjectMeta> for SnapshotProjectMeta {\n    type Error = anyhow::Error;\n\n    fn try_from(meta: &ProjectMeta) -> Result<Self> {\n        let target_commit_id = meta.target_commit_id_or_err()?;\n        if target_commit_id.is_null() {\n            bail!(\"cannot snapshot a null target commit id\");\n        }\n        Ok(Self {\n            target_ref: meta.target_ref.as_ref().map(ToString::to_string),\n            target_commit_id: target_commit_id.to_string(),\n            push_remote: meta.push_remote.clone(),\n        })\n    }\n}\n\nimpl TryFrom<SnapshotProjectMeta> for ProjectMeta {\n    type Error = anyhow::Error;\n\n    fn try_from(meta: SnapshotProjectMeta) -> Result<Self> {\n        let target_ref = meta\n            .target_ref\n            .map(|name| {\n                let name: gix::refs::FullName = name\n                    .try_into()","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-oplog/src/oplog.rs#L59-L95","documentation":"When recording an oplog snapshot, SnapshotProjectMeta is built from project metadata. The project's target commit id is mandatory for a snapshot; if target_commit_id_or_err() returns a null ObjectId (all zeros), the snapshot would be meaningless, so try_from bails. This protects the undo/timeline from recording snapshots pointing at nothing.","triggerScenarios":"Creating any oplog snapshot (SnapshotDetails via the snapshot wrapper pattern) for a project whose ProjectMeta has a null target_commit_id - e.g. before the target branch was ever resolved/created, or metadata persisted in a broken state.","commonSituations":"A freshly initialized project whose default target hasn't been pushed/created yet; corrupted or hand-edited project metadata; a migration/version mismatch leaving target_commit_id unset; tests constructing ProjectMeta manually without a target.","solutions":["Ensure the project's target branch exists and target_commit_id is set before triggering snapshot-recording operations.","Re-assign the workspace/target (re-initialize the project) to repair the null target commit id.","Skip oplog snapshotting (or use *_only* variants) for operations run before target initialization.","Inspect the project metadata storage to see why the target id is null and fix the source of the bad value."],"exampleFix":"// before\nlet snap = snapshot_project_meta(&ctx)?; // bails if target is null\n// after\nlet meta = project_meta(&ctx)?;\nif meta.target_commit_id_or_err()?.is_null() {\n    return Ok(None); // no snapshot possible before target init\n}\nlet snap = Some(SnapshotProjectMeta::try_from(&meta)?);","handlingStrategy":"validation","validationCode":"let target = project_meta(&ctx)?.target_commit_id_or_err()?;\nif target.is_null() { /* skip snapshot or initialize target first */ }","typeGuard":"fn has_valid_target(meta: &ProjectMeta) -> bool {\n    meta.target_commit_id_or_err().map(|id| !id.is_null()).unwrap_or(false)\n}","tryCatchPattern":"match SnapshotProjectMeta::try_from(&meta) {\n    Err(e) if e.to_string().contains(\"null target commit id\") => return Ok(None), // skip snapshot\n    other => other?,\n}","preventionTips":["Initialize the project target (remote branch) before any snapshot-recorded mutations","Use *_only* API variants for pre-initialization operations that need no undo entry","Validate ProjectMeta after loading a project and repair null targets early"],"tags":["git","oplog","snapshot","null-value","project-metadata"],"backgroundTag":"null-argument","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}