FuelLabs/sway · error · anyhow::Error
{}
Error message
{} What it means
Git URLs in Forc.toml dependencies are parsed with gix_url::Url::from_bytes. Malformed URLs - missing scheme, invalid characters, unsupported syntax - fail parsing, and the underlying gix error string is rethrown from the FromStr implementation.
Source
Thrown at forc-pkg/src/source/git/mod.rs:273
}
}
impl fmt::Display for Reference {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Reference::Branch(ref s) => write!(f, "branch={s}"),
Reference::Tag(ref s) => write!(f, "tag={s}"),
Reference::Rev(ref _s) => write!(f, "rev"),
Reference::DefaultBranch => write!(f, "default-branch"),
}
}
}
impl FromStr for Url {
type Err = anyhow::Error;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
let url = gix_url::Url::from_bytes(s.as_bytes().into()).map_err(|e| anyhow!("{}", e))?;
Ok(Self { url })
}
}
impl FromStr for Pinned {
type Err = PinnedParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
// git+<url/to/repo>?<reference>#<commit>
let s = s.trim();
// Check for "git+" at the start.
let prefix_plus = format!("{}+", Self::PREFIX);
if s.find(&prefix_plus) != Some(0) {
return Err(PinnedParseError::Prefix);
}
let s = &s[prefix_plus.len()..];
// Parse the `repo` URL.View on GitHub (pinned to 47e5e902fa)
Solutions
- Use a fully qualified URL: git = "https://github.com/FuelLabs/sway"
- For SSH, use the full ssh URL form: ssh://git@github.com/FuelLabs/sway.git
- Validate the URL with `git ls-remote <url>` before adding it to Forc.toml
Example fix
# before
[dependencies]
lib = { git = "github.com/org/lib" }
# after
[dependencies]
lib = { git = "https://github.com/org/lib" } Defensive patterns
Strategy: validation
Validate before calling
fn validate_git_urls(urls: &[String]) -> anyhow::Result<()> {
for url in urls {
gix_url::Url::from_bytes(url.as_bytes().into())
.with_context(|| format!("invalid git url: {url}"))?;
}
Ok(())
} Type guard
fn is_valid_git_url(s: &str) -> bool {
gix_url::Url::from_bytes(s.as_bytes().into()).is_ok()
} Prevention
- Use full https:// URLs copied from the browser address bar
- For SSH use ssh://git@host/org/repo.git form
- Add a CI check that parses every git URL in Forc.toml
When it happens
Trigger: Writing git = "github.com/FuelLabs/sway" (no scheme), URLs containing spaces or invalid characters, or URL forms gix does not support.
Common situations: Copy-pasting repo paths from a browser address bar minus the https:// prefix; typos; assuming scp-style shorthand like git@github.com:org/repo parses (it must be a URL form gix understands).
Related errors
- failed to parse dependency "{}": {}
- missing closing parenthesis
- missing pkg string
- invalid salt in lock file: {e}
- failed to parse manifest: {}.
AI-assisted analysis of FuelLabs/sway@47e5e902fa (2026-08-16).
Data as JSON: /api/errors/9de7d20fd3e569e7.
Report an issue: GitHub.