Skip to content

Conversation

ryzhak
Copy link
Contributor

@ryzhak ryzhak commented Jul 8, 2025

Resolves #4533

Right now there's an issue on generating docs which is reproducible in a default forge project:

// works fine
forge doc --out docs 

 // throws "Error: prefix not found"
forge doc --out ./docs

The root cause of the issue is this line. Somehow Path::strip_prefix strips "extra" characters in path, example:

let path_str = "/my/path/./../other1/other2";
let path = Path::new(path_str);
let prefix = "/my/path";
let result = path.strip_prefix(prefix);
println!("<Path> {:?}", result); // <Path> Ok("../other1/other2")

Notice that in the example above the ./ part is also stripped while it was not mentioned in the prefix. Interestingly there is also the String::strip_prefix method which actually works as expected (doesn't strip "extra" characters which can be seen in this rust playground).

What happens here is (roughly) that Path::new("/project/./../project/docs").strip_prefix("/project") returns ../project/docs instead of ./../project/docs which produces the Prefix not found error on subsequent strip_prefix calls.

There're many places where strip_prefix is used (in the forge-doc crate) so I suppose the simplest solution is to remove the ./ prefix from the out option.

Notes:

  • probably there's an easier way to achieve the same result via clap arguments
  • not sure how it affects windows users

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@onbjerg
Copy link
Contributor

onbjerg commented Aug 22, 2025

This is because the output directory is not canonicalized here. I've opened up a more comprehensive fix in #11406 (I added you as a co-author)

Thanks for thoroughly investigating this, and sorry for the slow response times. We'll do better.

@onbjerg onbjerg closed this Aug 22, 2025
@github-project-automation github-project-automation bot moved this to Done in Foundry Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

forge doc --build --root <PATH> --prefix not found error
2 participants