Skip to content

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

@rami3l

Description

@rami3l

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: A bug, incorrect or unintended behavior

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions