Improve error message for invalid Font Awesome icons

When an invalid Font Awesome icon name is used (e.g. in git-repository-icon),
the error message now includes the icon name, the type that was searched,
valid prefix options (fas/fab/far), and a link to the FontAwesome icon gallery.

Before: Missing font github
After:  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

Fixes #3023
This commit is contained in:
cobyfrombrooklyn-bot 2026-02-24 08:58:05 -05:00
parent 424d6a4dbd
commit d171e698fa
5 changed files with 38 additions and 4 deletions

View file

@ -43,10 +43,14 @@ pub(crate) fn fa_helper(
} else {
out.write("<span class=fa-svg>")?;
}
out.write(
fa::svg(type_, name)
.map_err(|_| RenderErrorReason::Other(format!("Missing font {}", name)))?,
)?;
out.write(fa::svg(type_, name).map_err(|_| {
let valid_types = "fas (solid), fab (brands), or far (regular)";
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>")?;
Ok(())

View file

@ -60,6 +60,24 @@ fn fontawesome() {
.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.
#[test]
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!