Fails to strip_prefix the git root path #16

Closed
opened 2024-05-11 15:04:50 +00:00 by HaaiHenkie · 6 comments
HaaiHenkie commented 2024-05-11 15:04:50 +00:00 (Migrated from github.com)

Hello,

I am trying to run a site locally on Windows for https://github.com/freeplane/docs.

I have downloaded and unzipped the following pre-compiled binaries for Windows and added them to my path:
mdbook-v0.4.37-x86_64-pc-windows-msvc.zip
mdbook-toc-0.14.2-x86_64-pc-windows-msvc.zip
mdbook-open-on-gh-2.4.2-x86_64-pc-windows-msvc.zip

I have cloned freeplane/doc to a local repository under Windows.

From a windows command prompt I run the command as per freeplane/docs README instructions from the repository root directory and I receive the following error messages:

C:\ws\git\freeplane-docs>mdbook serve src --dest-dir ../build/gh-pages -p 3000
2024-05-11 16:11:46 [INFO] (mdbook::book): Book building has started
Warning: The mdbook-open-on-gh preprocessor was built against version 0.4.36 of mdbook, but we're being called from version 0.4.37
thread 'main' panicked at src\lib.rs:113:47:
called `Result::unwrap()` on an `Err` value: StripPrefixError(())
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
2024-05-11 16:11:46 [ERROR] (mdbook::utils): Error: The "open-on-gh" preprocessor exited unsuccessfully with exit code: 101 status

I haver tried several versions of mdbook and mdbook-open-on-gh, but keep on getting the same errors.

I tried the same under Linux and it worked.

How to get this working under Windows. Am I missing something?

Hello, I am trying to run a site locally on Windows for https://github.com/freeplane/docs. I have downloaded and unzipped the following pre-compiled binaries for Windows and added them to my path: mdbook-v0.4.37-x86_64-pc-windows-msvc.zip mdbook-toc-0.14.2-x86_64-pc-windows-msvc.zip mdbook-open-on-gh-2.4.2-x86_64-pc-windows-msvc.zip I have cloned freeplane/doc to a local repository under Windows. From a windows command prompt I run the command as per freeplane/docs README instructions from the repository root directory and I receive the following error messages: ``` C:\ws\git\freeplane-docs>mdbook serve src --dest-dir ../build/gh-pages -p 3000 2024-05-11 16:11:46 [INFO] (mdbook::book): Book building has started Warning: The mdbook-open-on-gh preprocessor was built against version 0.4.36 of mdbook, but we're being called from version 0.4.37 thread 'main' panicked at src\lib.rs:113:47: called `Result::unwrap()` on an `Err` value: StripPrefixError(()) note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace 2024-05-11 16:11:46 [ERROR] (mdbook::utils): Error: The "open-on-gh" preprocessor exited unsuccessfully with exit code: 101 status ``` I haver tried several versions of mdbook and mdbook-open-on-gh, but keep on getting the same errors. I tried the same under Linux and it worked. How to get this working under Windows. Am I missing something?
HaaiHenkie commented 2024-05-12 08:55:06 +00:00 (Migrated from github.com)

With RUST_BACKTRACE=full I get the following output:

C:\ws\git\freeplane-docs>mdbook serve src --dest-dir ../build/gh-pages -p 3000
2024-05-12 10:52:15 [INFO] (mdbook::book): Book building has started
Warning: The mdbook-open-on-gh preprocessor was built against version 0.4.36 of mdbook, but we're being called from version 0.4.37
thread 'main' panicked at src\lib.rs:113:47:
called `Result::unwrap()` on an `Err` value: StripPrefixError(())
stack backtrace:
   0:     0x7ff6b1b9b0da - <unknown>
   1:     0x7ff6b1bb155b - <unknown>
   2:     0x7ff6b1b97d91 - <unknown>
   3:     0x7ff6b1b9ae5a - <unknown>
   4:     0x7ff6b1b9ce4a - <unknown>
   5:     0x7ff6b1b9cab8 - <unknown>
   6:     0x7ff6b1b9d4f8 - <unknown>
   7:     0x7ff6b1b9d3dd - <unknown>
   8:     0x7ff6b1b9bac9 - <unknown>
   9:     0x7ff6b1b9d0f0 - <unknown>
  10:     0x7ff6b1bc0a77 - <unknown>
  11:     0x7ff6b1bc0f33 - <unknown>
  12:     0x7ff6b1a54060 - <unknown>
  13:     0x7ff6b1a5461c - <unknown>
  14:     0x7ff6b1a53455 - <unknown>
  15:     0x7ff6b1a43c7d - <unknown>
  16:     0x7ff6b1a431f6 - <unknown>
  17:     0x7ff6b1a3f8ac - <unknown>
  18:     0x7ff6b1b93268 - <unknown>
  19:     0x7ff6b1a4442c - <unknown>
  20:     0x7ff6b1bb8a48 - <unknown>
  21:     0x7ffc9b81257d - BaseThreadInitThunk
  22:     0x7ffc9c4eaa48 - RtlUserThreadStart
2024-05-12 10:52:15 [ERROR] (mdbook::utils): Error: The "open-on-gh" preprocessor exited unsuccessfully with exit code: 101 status
With `RUST_BACKTRACE=full` I get the following output: ``` C:\ws\git\freeplane-docs>mdbook serve src --dest-dir ../build/gh-pages -p 3000 2024-05-12 10:52:15 [INFO] (mdbook::book): Book building has started Warning: The mdbook-open-on-gh preprocessor was built against version 0.4.36 of mdbook, but we're being called from version 0.4.37 thread 'main' panicked at src\lib.rs:113:47: called `Result::unwrap()` on an `Err` value: StripPrefixError(()) stack backtrace: 0: 0x7ff6b1b9b0da - <unknown> 1: 0x7ff6b1bb155b - <unknown> 2: 0x7ff6b1b97d91 - <unknown> 3: 0x7ff6b1b9ae5a - <unknown> 4: 0x7ff6b1b9ce4a - <unknown> 5: 0x7ff6b1b9cab8 - <unknown> 6: 0x7ff6b1b9d4f8 - <unknown> 7: 0x7ff6b1b9d3dd - <unknown> 8: 0x7ff6b1b9bac9 - <unknown> 9: 0x7ff6b1b9d0f0 - <unknown> 10: 0x7ff6b1bc0a77 - <unknown> 11: 0x7ff6b1bc0f33 - <unknown> 12: 0x7ff6b1a54060 - <unknown> 13: 0x7ff6b1a5461c - <unknown> 14: 0x7ff6b1a53455 - <unknown> 15: 0x7ff6b1a43c7d - <unknown> 16: 0x7ff6b1a431f6 - <unknown> 17: 0x7ff6b1a3f8ac - <unknown> 18: 0x7ff6b1b93268 - <unknown> 19: 0x7ff6b1a4442c - <unknown> 20: 0x7ff6b1bb8a48 - <unknown> 21: 0x7ffc9b81257d - BaseThreadInitThunk 22: 0x7ffc9c4eaa48 - RtlUserThreadStart 2024-05-12 10:52:15 [ERROR] (mdbook::utils): Error: The "open-on-gh" preprocessor exited unsuccessfully with exit code: 101 status ```
badboy commented 2024-05-13 09:06:45 +00:00 (Migrated from github.com)

It's this line: badboy/mdbook-open-on-gh@24c3c8cd26/src/lib.rs (L113)

Error message could be improved. Essentially this tries to remove the path to the git repository from the beginning of the string.
So: Is C:\ws\git\freeplane-docs a correct git repository?

You could modify the code and insert a dbg!(path, git_root); directly above that line (I think), run it and see what the values are.
I don't have a Windows machine around to test it myself.

It's this line: https://github.com/badboy/mdbook-open-on-gh/blob/24c3c8cd2695a19e6ea777838cce6fe6326ad078/src/lib.rs#L113 Error message could be improved. Essentially this tries to remove the path to the git repository from the beginning of the string. So: Is `C:\ws\git\freeplane-docs` a correct git repository? You could modify the code and insert a `dbg!(path, git_root);` directly above that line (I think), run it and see what the values are. I don't have a Windows machine around to test it myself.
HaaiHenkie commented 2024-05-13 11:17:06 +00:00 (Migrated from github.com)

Hi,

I could not compile because of this error:

error[E0382]: borrow of moved value: `path`
   --> src\lib.rs:114:19
    |
109 |     let path = match src_root.join(&path).canonicalize() {
    |         ---- move occurs because `path` has type `PathBuf`, which does not implement the `Copy` trait
...
113 |     dbg!(path, git_root);
    |     -------------------- value moved here
114 |     let relpath = path.strip_prefix(git_root).unwrap();
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^ value borrowed here after move
    |
    = note: borrow occurs due to deref coercion to `Path`

So I changed line 113 into: dbg!(&path, git_root);

That resulted in a successful compilation. When running the same mdbook command following 2 lines are added to the output:

[src\lib.rs:113:5] &path = "\\\\?\\C:\\ws\\git\\freeplane-docs\\src\\docs\\home.md"
[src\lib.rs:113:5] git_root = "C:\\ws\\git\\freeplane-docs"

It is the correct git repository. Only the leading \\\\?\\ in path looks strange to me.

Hi, I could not compile because of this error: ``` error[E0382]: borrow of moved value: `path` --> src\lib.rs:114:19 | 109 | let path = match src_root.join(&path).canonicalize() { | ---- move occurs because `path` has type `PathBuf`, which does not implement the `Copy` trait ... 113 | dbg!(path, git_root); | -------------------- value moved here 114 | let relpath = path.strip_prefix(git_root).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ value borrowed here after move | = note: borrow occurs due to deref coercion to `Path` ``` So I changed line 113 into: ` dbg!(&path, git_root);` That resulted in a successful compilation. When running the same mdbook command following 2 lines are added to the output: ``` [src\lib.rs:113:5] &path = "\\\\?\\C:\\ws\\git\\freeplane-docs\\src\\docs\\home.md" [src\lib.rs:113:5] git_root = "C:\\ws\\git\\freeplane-docs" ``` It is the correct git repository. Only the leading `\\\\?\\` in `path` looks strange to me.
badboy commented 2024-05-13 11:30:05 +00:00 (Migrated from github.com)

That's a UNC path.
Thanks! That helps.
Maybe we need to canonicalize git_root too.
Try replacing (now) line 114 with:

let relpath = path.strip_prefix(git_root.canonicalize().unwrap()).unwrap();
That's a [UNC path](https://en.wikipedia.org/wiki/Path_(computing)#UNC). Thanks! That helps. Maybe we need to canonicalize `git_root` too. Try replacing (now) line 114 with: ``` let relpath = path.strip_prefix(git_root.canonicalize().unwrap()).unwrap(); ```
HaaiHenkie commented 2024-05-13 11:39:14 +00:00 (Migrated from github.com)

Yes it is working now, despite dbg!(&path, git_root); generating output for every path now.

Yes it is working now, despite `dbg!(&path, git_root);` generating output for every path now.
badboy commented 2024-05-13 12:06:43 +00:00 (Migrated from github.com)

Yes it is working now, despite dbg!(&path, git_root); generating output for every path now.

To be expected ;) -- this was merely to debug the whole thing. I can now fix the code properly.

> Yes it is working now, despite `dbg!(&path, git_root);` generating output for every path now. To be expected ;) -- this was merely to debug the whole thing. I can now fix the code properly.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jer/mdbook-open-on-gh#16
No description provided.