rust-lang / rust-lang/mdBook

Validate html config

Open
#2,984 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-Configuration C-bug
Dominant language
Rust
Stars
22.2k
Forks
1.9k
PR merge metrics
PR metrics pending

Description

Problem

Currently if there is an error in the HTML config, mdbook prints an error, but does not fail the build.

Steps

Create a book.toml with an invalid HTML config:

[book]
title = "foo"

[output.html]
foo = 123

With the current output:

 INFO Book building has started
 INFO Running the html backend
ERROR Failed to deserialize `output.html`
	Caused by: unknown field `foo`, expected one of `theme`, `default-theme`, `preferred-dark-theme`, `smart-punctuation`, `definition-lists`, `admonitions`, `mathjax-support`, `additional-css`, `additional-js`, `fold`, `playground`, `playpen`, `code`, `print`, `no-section-label`, `search`, `git-repository-url`, `git-repository-icon`, `input-404`, `site-url`, `cname`, `edit-url-template`, `live-reload-endpoint`, `redirect`, `hash-files`, `sidebar-header-nav`

 INFO HTML book written to `/Users/eric/Temp/foo/book`
Possible Solution(s)

I think the solution should be to change Config.html_config to return a Result. This can be a little awkward in some places, but I think is probably the best solution. Since this is an "internal" function (doc-hidden), I think it should be OK to make a breaking change to it.

Notes

No response

Version
mdbook v0.5.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating Config.html_config and its callers, then reproduce the issue with the invalid book.toml shown in the report. Trace how the HTML configuration error is logged and confirm that a completed change makes the build fail instead of writing the book; add or update coverage for this invalid configuration if the surrounding tests provide a suitable entry point.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.