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

mdBook fails to open the web browser upon mdbook build --open, if the first link in the summary is a draft chapter (or no links exist in the summary) #1713

Closed
LikeLakers2 opened this issue Dec 28, 2021 · 2 comments · Fixed by #1714

Comments

@LikeLakers2
Copy link

LikeLakers2 commented Dec 28, 2021

(Hope you don't mind, but I'm going to use a template similar to Godot Engine's issue template. Makes it easier to read the issue, in my opinion. :D )

mdBook version:
mdbook v0.4.14, installed via cargo install mdbook, compiled via the stable-x86_64-pc-windows-msvc toolchain (currently rustc 1.57.0 (f1edd0429 2021-11-29) as of this issue posting)

Issue description:
mdBook fails to open the web browser upon building the book, when building using mdbook build --open, if one of the following conditions are met:

  • The first link in SUMMARY.md is a draft chapter (e.g. [Chapter 1]())
  • The SUMMARY.md file is devoid of links.

If either of these conditions are met, then mdBook returns an error upon trying to mdbook build --open:

[INFO] (mdbook): Opening web browser
[ERROR] (mdbook): Error opening web browser: IO error

with no further detail on what this IO error is.

I would expect mdBook to cover these cases, most likely in the following ways:

  • If the first link in SUMMARY.md is a draft chapter, then I would expect it to look to the next chapter, and the next, and the next, etc... until it finds a valid link, which it opens the web browser to.
  • If mdBook cannot find a valid link, I would expect it to return an error saying as such. For example, "Could not find a valid book page to open to!"

Steps to reproduce:

  1. In the SUMMARY.md file of any book (even a freshly-created book), add a new draft chapter above all other chapters, such as [Chapter 1]().
  2. Attempt to build with the --open parameter, asking mdBook to open the resulting book afterwards.
  3. Observe that mdBook will return a vague "IO error".

Minimal reproduction project:
mdbook-issue-1713.zip

@LikeLakers2 LikeLakers2 changed the title mdBook returns an "IO error" upon trying to open the web browser, when the first link in the summary is a draft chapter, or when there are no links in the summary mdBook fails to open the web browser upon mdbook build --open, if the first link in the summary is not valid Dec 28, 2021
@LikeLakers2 LikeLakers2 changed the title mdBook fails to open the web browser upon mdbook build --open, if the first link in the summary is not valid mdBook fails to open the web browser upon mdbook build --open, if the first link in the summary is a draft chapter (or no links exist in the summary) Dec 28, 2021
@joshrotenberg
Copy link
Contributor

joshrotenberg commented Dec 29, 2021

My guess after looking for a couple minutes: with --open the build command opens the path explicitly to the book's index.html but if the chapter is a draft that file never gets created. Maybe just a better error is the right way to handle this; check that the file exists before calling open and quit with an error from mdbook first.

@LikeLakers2
Copy link
Author

LikeLakers2 commented Dec 29, 2021

@joshrotenberg Please ignore my (now-deleted) comment -- I misinterpreted what was going on, and I also misinterpreted what you said. It seems that what you're saying is right.

That said, while I'm not opposed to your solution (it helps with the issue), I would still prefer if mdBook used the first non-draft-chapter as index.html, instead of erroring out if the first chapter is a draft chapter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants