Merge pull request #3037 from cobyfrombrooklyn-bot/fix-issue-3023

Fix #3023: Improve error message for invalid Font Awesome icons
This commit is contained in:
Eric Huss 2026-02-27 14:13:02 +00:00 committed by GitHub
commit 33f76c0a30
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 38 additions and 4 deletions

View file

@ -43,10 +43,14 @@ pub(crate) fn fa_helper(
} else { } else {
out.write("<span class=fa-svg>")?; out.write("<span class=fa-svg>")?;
} }
out.write( out.write(fa::svg(type_, name).map_err(|_| {
fa::svg(type_, name) let valid_types = "fas (solid), fab (brands), or far (regular)";
.map_err(|_| RenderErrorReason::Other(format!("Missing font {}", name)))?, RenderErrorReason::Other(format!(
)?; "Unknown Font Awesome icon `{name}` for type `{type_}`. \
Hint: check the icon name and prefix ({valid_types}) at \
https://fontawesome.com/v6/search?m=free"
))
})?)?;
out.write("</span>")?; out.write("</span>")?;
Ok(()) Ok(())

View file

@ -60,6 +60,24 @@ fn fontawesome() {
.check_all_main_files(); .check_all_main_files();
} }
// Verifies that an invalid `git-repository-icon` in book.toml produces a
// helpful error message with the icon name, type, and a link to FontAwesome.
#[test]
fn fontawesome_error_message() {
BookTest::from_dir("rendering/fontawesome_error")
.run("build", |cmd| {
cmd.expect_failure();
cmd.expect_stderr(str![[r#"
INFO Book building has started
INFO Running the html backend
ERROR Rendering failed
[TAB]Caused by: Error rendering "index" line [..], col [..]: Unknown Font Awesome icon `github` for type `regular`. Hint: check the icon name and prefix (fas (solid), fab (brands), or far (regular)) at https://fontawesome.com/v6/search?m=free
[TAB]Caused by: Unknown Font Awesome icon `github` for type `regular`. Hint: check the icon name and prefix (fas (solid), fab (brands), or far (regular)) at https://fontawesome.com/v6/search?m=free
"#]]);
});
}
// Tests the rendering when setting the default rust edition. // Tests the rendering when setting the default rust edition.
#[test] #[test]
fn default_rust_edition() { fn default_rust_edition() {

View file

@ -0,0 +1,6 @@
[book]
title = "fontawesome_error"
[output.html]
git-repository-url = "https://github.com/example/test"
git-repository-icon = "fa-github"

View file

@ -0,0 +1,3 @@
# Summary
- [Chapter 1](./chapter_1.md)

View file

@ -0,0 +1,3 @@
# Chapter 1
Hello, world!