{"record":{"id":"eddce22c5b4340ef","repo":"GitoxideLabs/gitoxide","slug":"receive-can-only-be-called-once","errorCode":null,"errorMessage":"receive() can only be called once","messagePattern":"receive\\(\\) can only be called once","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix/src/remote/connection/fetch/receive_pack.rs","lineNumber":108,"sourceCode":"        repo: &crate::Repository,\n        progress: P,\n        should_interrupt: &AtomicBool,\n    ) -> Result<Outcome, Error>\n    where\n        P: gix_features::progress::NestedProgress,\n        P::SubProgress: 'static,\n    {\n        let ref_map = &self.ref_map;\n        if ref_map.is_missing_required_mapping() {\n            let mut specs = ref_map.refspecs.clone();\n            specs.extend(ref_map.extra_refspecs.clone());\n            return Err(Error::NoMapping {\n                refspecs: specs,\n                num_remote_refs: ref_map.remote_refs.len(),\n            });\n        }\n\n        let mut con = self.con.take().expect(\"receive() can only be called once\");\n        let mut handshake = con.handshake.take().expect(\"receive() can only be called once\");\n\n        let expected_object_hash = repo.object_hash();\n        if ref_map.object_hash != expected_object_hash {\n            return Err(Error::IncompatibleObjectHash {\n                local: expected_object_hash,\n                remote: ref_map.object_hash,\n            });\n        }\n\n        let fetch_options = gix_protocol::fetch::Options {\n            shallow_file: repo.shallow_file(),\n            shallow: &self.shallow,\n            tags: con.remote.fetch_tags,\n            reject_shallow_remote: Clone::REJECT_SHALLOW\n                .enrich_error(\n                    repo.config\n                        .resolved","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix/src/remote/connection/fetch/receive_pack.rs#L90-L126","documentation":"`FetchConnection::receive()` consumes the connection (`self.con.take()`) so it can only be called once; a second call finds `None` and the `expect` panics. It is an intentional misuse guard: the receive phase hands ownership of the connection and handshake to the streaming result. Any follow-up operation requires setting up a new connection/fetch.","triggerScenarios":"Calling `.receive()` twice on the same `receive_pack` value, e.g. storing the result and calling `receive()` again after an earlier call succeeded or after partial consumption.","commonSituations":"Retry logic that re-invokes `receive()` on the same object instead of redialing; wrapping code that calls receive in a helper called more than once.","solutions":["Call `receive()` exactly once per fetch connection; restructure code so the result is stored, not re-obtained.","For a new fetch, create a new connection via `remote.connect(Direction::Fetch)` and restart the handshake.","If you need the value repeatedly, clone/extract needed data (refs, pack) from the single receive result before dropping it."],"exampleFix":"// before\nlet first = receive_pack.receive()?;\nlet again = receive_pack.receive()?; // panic\n// after\nlet first = receive_pack.receive()?; // consume once\n// for more data, reconnect:\nlet mut con = remote.connect(gix::remote::Direction::Fetch)?;","handlingStrategy":"validation","validationCode":"// track consumption yourself\nlet mut received = false;\nif received { return Err(anyhow::anyhow!(\"receive() already called\")); }\nreceived = true;\nlet result = receive_pack.receive()?;\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat receive() as a consuming one-shot: take ownership and move the result","Never call receive() inside loops or retry helpers on the same value","Reconnect (remote.connect) for every additional fetch"],"tags":["panic","misuse","state-machine","fetch","git"],"backgroundTag":"invalid-state-transition","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}