Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected panic 'path is expected to be under the root' #2228

Closed
rami3l opened this issue Oct 30, 2023 · 2 comments
Closed

Unexpected panic 'path is expected to be under the root' #2228

rami3l opened this issue Oct 30, 2023 · 2 comments
Assignees
Labels
C-bug Category: A bug, incorrect or unintended behavior

Comments

@rami3l
Copy link
Member

rami3l commented Oct 30, 2023

Problem

When maintaining official rustup docs, I have noticed that mdbook serve will work at first but fail immediately after a file update, which can break my workflow quite often:

> mdbook serve ./doc/user-guide --open
2023-10-30 17:17:41 [INFO] (mdbook::book): Book building has started
2023-10-30 17:17:41 [INFO] (mdbook::book): Running the html backend
2023-10-30 17:17:41 [INFO] (mdbook::cmd::serve): Serving on: http://localhost:3000
2023-10-30 17:17:41 [INFO] (mdbook): Opening web browser
2023-10-30 17:17:41 [INFO] (warp::server): Server::run; addr=[::1]:3000
2023-10-30 17:17:41 [INFO] (warp::server): listening on http://[::1]:3000
2023-10-30 17:17:41 [INFO] (mdbook::cmd::watch): Listening for changes...
2023-10-30 17:21:24 [ERROR] (mdbook::cmd::serve): Unable to serve: panicked at 'path is expected to be under the root', /Users/brew/Library/Caches/Homebrew/cargo_cache/registry/src/index.crates.io-6f17d22bba15001f/ignore-0.4.20/src/gitignore.rs:227:9

Steps

  1. git clone https://github.com/rust-lang/rustup.git && cd rustup
  2. mdbook serve ./doc/user-guide --open
  3. Change anything under ./doc/user-guide and observe the panic

Possible Solution(s)

I'm not sure what this error message is about, but .matched_path_or_any_parents(path, path.is_dir()) requires path to be absolute. Maybe at some point down the business logic we need to canonicalize the path so it can appear to "be under the root":

mdBook/src/cmd/watch.rs

Lines 89 to 99 in 94e0a44

fn filter_ignored_files(ignore: Gitignore, paths: &[PathBuf]) -> Vec<PathBuf> {
paths
.iter()
.filter(|path| {
!ignore
.matched_path_or_any_parents(path, path.is_dir())
.is_ignore()
})
.map(|path| path.to_path_buf())
.collect()
}

Notes

No response

Version

> mdbook --version
mdbook v0.4.35
@rami3l rami3l added the C-bug Category: A bug, incorrect or unintended behavior label Oct 30, 2023
@leonzchang
Copy link
Contributor

leonzchang commented Oct 30, 2023

I would like to take this one.
@rustbot claim

@rami3l
Copy link
Member Author

rami3l commented Nov 30, 2023

Closed by #2229 and released with 0.4.36.

@rami3l rami3l closed this as completed Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: A bug, incorrect or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants