{"record":{"id":"dcfd1287fecf26ef","repo":"FuelLabs/sway","slug":"unable-to-fetch-pkg-from-in-offline-mod","errorCode":null,"errorMessage":"Unable to fetch pkg {:?} from  {:?} in offline mode","messagePattern":"Unable to fetch pkg (.+?) from  (.+?) in offline mode","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"forc-pkg/src/source/git/mod.rs","lineNumber":160,"sourceCode":"            Reference::Rev(s) => resolve_rev(repo, s),\n        }\n    }\n}\n\nimpl Pinned {\n    pub const PREFIX: &'static str = \"git\";\n}\n\nimpl source::Pin for Source {\n    type Pinned = Pinned;\n    fn pin(&self, ctx: source::PinCtx) -> Result<(Self::Pinned, PathBuf)> {\n        // If the git source directly specifies a full commit hash, we should check\n        // to see if we have a local copy. Otherwise we cannot know what commit we should pin\n        // to without fetching the repo into a temporary directory.\n        let pinned = if ctx.offline() {\n            let (_local_path, commit_hash) =\n                search_source_locally(ctx.name(), self)?.ok_or_else(|| {\n                    anyhow!(\n                        \"Unable to fetch pkg {:?} from  {:?} in offline mode\",\n                        ctx.name(),\n                        self.repo\n                    )\n                })?;\n            Pinned {\n                source: self.clone(),\n                commit_hash,\n            }\n        } else if let Reference::DefaultBranch | Reference::Branch(_) = self.reference {\n            // If the reference is to a branch or to the default branch we need to fetch\n            // from remote even though we may have it locally. Because remote may contain a\n            // newer commit.\n            pin(ctx.fetch_id(), ctx.name(), self.clone())?\n        } else {\n            // If we are in online mode and the reference is to a specific commit (tag or\n            // rev) we can first search it locally and re-use it.\n            match search_source_locally(ctx.name(), self) {","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc-pkg/src/source/git/mod.rs#L142-L178","documentation":"With offline mode enabled, the git source's pin() refuses network access and instead searches local checkouts (search_source_locally) to find an existing commit. If no cached checkout of that repo/reference exists under the git checkouts directory, pinning cannot determine a commit hash and this error names the package and repo URL.","triggerScenarios":"Running any forc command with --offline (offline=true in PinCtx) for the first time on a machine whose git dependencies were never fetched, or after the cache was cleaned.","commonSituations":"Air-gapped or CI machines requiring warm caches; new clones combined with a --offline habit; forc clean removing the checkouts directory.","solutions":["Run the same command once without --offline to populate the git checkouts cache, then go offline","Pre-populate the cache (copy ~/.forc/git/checkouts from a machine that built successfully, or pre-fetch in a Docker build layer)","Pin the git dependency to a rev/branch you have already fetched so search_source_locally can match it","Remove --offline if network access is actually available"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"use std::path::Path;\n\nfn git_dep_cached(checkouts: &Path, pkg_name: &str) -> bool {\n    std::fs::read_dir(checkouts)\n        .map(|entries| {\n            entries.filter_map(Result::ok)\n                .any(|e| e.file_name().to_string_lossy().starts_with(pkg_name))\n        })\n        .unwrap_or(false)\n}\n// before running with offline=true, require a warm cache:\n// assert git_dep_cached(&home.join(\".forc/git/checkouts\"), dep_name);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prime caches with one online build before any --offline run","Bake ~/.forc/git/checkouts into CI images for offline reproducibility","Treat --offline as cache-only mode: never use it on a fresh clone"],"tags":["git","offline","forc","cache","network"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}