{"id":"1a64f0fef4bd106d","repo":"rust-lang/cargo","slug":"unsupported-registry-protocol-unknown-defined","errorCode":null,"errorMessage":"unsupported registry protocol `{unknown}` (defined in {})","messagePattern":"unsupported registry protocol `(.+?)` \\(defined in (.+?)\\)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/workspace/source_id.rs","lineNumber":286,"sourceCode":"    /// sparse HTTP index if allowed.\n    pub fn crates_io_maybe_sparse_http(gctx: &GlobalContext) -> CargoResult<SourceId> {\n        if Self::crates_io_is_sparse(gctx)? {\n            gctx.check_registry_index_not_set()?;\n            let url = CRATES_IO_HTTP_INDEX.into_url().unwrap();\n            let key = KeyOf::Registry(CRATES_IO_REGISTRY.into());\n            SourceId::new(SourceKind::SparseRegistry, url, Some(key))\n        } else {\n            Self::crates_io(gctx)\n        }\n    }\n\n    /// Returns whether to access crates.io over the sparse protocol.\n    pub fn crates_io_is_sparse(gctx: &GlobalContext) -> CargoResult<bool> {\n        let proto: Option<context::Value<String>> = gctx.get(\"registries.crates-io.protocol\")?;\n        let is_sparse = match proto.as_ref().map(|v| v.val.as_str()) {\n            Some(\"sparse\") => true,\n            Some(\"git\") => false,\n            Some(unknown) => anyhow::bail!(\n                \"unsupported registry protocol `{unknown}` (defined in {})\",\n                proto.as_ref().unwrap().definition\n            ),\n            None => true,\n        };\n        Ok(is_sparse)\n    }\n\n    /// Gets the `SourceId` associated with given name of the remote registry.\n    pub fn alt_registry(gctx: &GlobalContext, key: &str) -> CargoResult<SourceId> {\n        if key == CRATES_IO_REGISTRY {\n            return Self::crates_io(gctx);\n        }\n        let url = gctx.get_registry_index(key)?;\n        Self::for_alt_registry(&url, key)\n    }\n\n    /// Gets this source URL.","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/workspace/source_id.rs#L268-L304","documentation":"Raised by `SourceId::crates_io_is_sparse` (src/workspace/source_id.rs:281) when the `registries.crates-io.protocol` config value is set to something other than the two accepted strings \"sparse\" or \"git\". Cargo only supports those two protocols for the crates.io index, so any third value (typos like \"spars\", \"http\", \"sparse-http\") causes an immediate `anyhow::bail!` that also reports the config `definition` (the file/line where the bad value was set).","triggerScenarios":"Setting `registries.crates-io.protocol` in `.cargo/config.toml` or `~/.cargo/config.toml` to a value that is neither `\"sparse\"` nor `\"git\"`. The branch `Some(unknown) =>` in the match at line 286 fires for any other string.","commonSituations":"Typing `protocol = \"spars\"` or `protocol = \"sparse\"` mis-capitalized; copying an outdated config snippet that used `\"http\"` or `\"https\"`; a CI image baking a wrong protocol value; cargo version downgrade where the value was once different.","solutions":["Set `registries.crates-io.protocol = \"sparse\"` (the modern default) or `\"git\"` in your `.cargo/config.toml`.","Remove the `registries.crates-io.protocol` line entirely — `None` defaults to sparse (line 290).","Check every config layer (`~/.cargo/config.toml`, repo `.cargo/config.toml`, `$CARGO_HOME/config.toml`) since the error names the offending `definition`."],"exampleFix":"# before\n[registries.crates-io]\nprotocol = \"spars\"\n# after\n[registries.crates-io]\nprotocol = \"sparse\"","handlingStrategy":"validation","validationCode":"fn valid_protocol(v: &str) -> bool { matches!(v, \"sparse\" | \"git\") }\n// before writing config: assert valid_protocol(value)","typeGuard":"const isProtocol = (v: unknown): v is \"sparse\" | \"git\" => v === \"sparse\" || v === \"git\";","tryCatchPattern":null,"preventionTips":["Only ever set `registries.crates-io.protocol` to \"sparse\" or \"git\".","Omit the key to get the safe default (sparse).","Lint config files for this key before committing."],"tags":["cargo","config","registry","crates-io","protocol"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}