{"id":"69d97a4fbca5d11c","repo":"rust-lang/cargo","slug":"was-not-filled-at-beginning-of-the-function","errorCode":null,"errorMessage":"was not filled at beginning of the function","messagePattern":"was not filled at beginning of the function","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/context/mod.rs","lineNumber":1824,"sourceCode":"\n        let mut credential_values = HashMap::default();\n        if let CV::Table(map, _) = value {\n            let base_map = self.values()?;\n            for (k, v) in map {\n                let entry = match base_map.get(&k) {\n                    Some(base_entry) => {\n                        let mut entry = base_entry.clone();\n                        entry.merge(v, true)?;\n                        entry\n                    }\n                    None => v,\n                };\n                credential_values.insert(k, entry);\n            }\n        }\n        self.credential_values\n            .set(credential_values)\n            .expect(\"was not filled at beginning of the function\");\n        Ok(())\n    }\n\n    /// Looks for a path for `tool` in an environment variable or the given config, and returns\n    /// `None` if it's not present.\n    fn maybe_get_tool(\n        &self,\n        tool: &str,\n        from_config: &Option<ConfigRelativePath>,\n    ) -> Option<PathBuf> {\n        let var = tool.to_uppercase();\n\n        match self.get_env_os(&var).as_ref().and_then(|s| s.to_str()) {\n            Some(tool_path) => {\n                let maybe_relative = tool_path.contains('/') || tool_path.contains('\\\\');\n                let path = if maybe_relative {\n                    self.cwd.join(tool_path)\n                } else {","sourceCodeStart":1806,"sourceCodeEnd":1842,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/context/mod.rs#L1806-L1842","documentation":"This panic is at the end of GlobalContext::load_credentials(). The function guards re-entry by checking self.credential_values.filled() at the top (line 1785) and returning Ok(()) early if already loaded. At line 1822-1824 it calls self.credential_values.set(credential_values) and expects success. The OnceCell .set() fails only if already filled — so if something filled credential_values between the top check and this call, the expect panics.","triggerScenarios":"A re-entrant or concurrent call to load_credentials() that fills the OnceCell between the filled() check on line 1785 and the set() on line 1824. Since load_credentials takes &self (not &mut self), concurrent calls are possible if the OnceCell is not otherwise synchronized.","commonSituations":"Embedding cargo as a library and calling load_credentials() from multiple threads simultaneously; a cargo internal code path that triggers credential loading recursively; corrupted credentials file causing a partial load that fills the cell before the full load completes.","solutions":["If embedding cargo as a library, call load_credentials() once at startup before spawning threads.","Synchronize access to GlobalContext credential loading with a mutex or ensure single-threaded init.","Verify the ~/.cargo/credentials file is not corrupted or concurrently modified."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Call load_credentials once at startup before any concurrent access\nctx.load_credentials()?;\n// Subsequent calls are no-ops due to the filled() guard","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Initialize credentials once at startup in single-threaded context before spawning workers.","Do not call load_credentials() from multiple threads without synchronization.","Ensure ~/.cargo/credentials is not concurrently modified by external processes."],"tags":["rust","cargo","panic","invariant","credentials","once-cell","concurrency"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}