Skip to content

Commit f51d89b

Browse files
committed
Move error types to mdbook-core
This moves Result and Error to mdbook-core with the anticipation of using them in user crates. For now, the internal APIs will be using anyhow directly, but the intent is to transition more of these to mdbook-core where it makes sense.
1 parent 461884f commit f51d89b

File tree

34 files changed

+66
-64
lines changed

34 files changed

+66
-64
lines changed

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ repository = "https://github.com/rust-lang/mdBook"
2121
rust-version = "1.85.0" # Keep in sync with installation.md and .github/workflows/main.yml
2222

2323
[workspace.dependencies]
24+
anyhow = "1.0.98"
2425
mdbook-core = { path = "crates/mdbook-core" }
2526

2627
[package]
@@ -42,7 +43,7 @@ description = "Creates a book from markdown files"
4243
rust-version.workspace = true
4344

4445
[dependencies]
45-
anyhow = "1.0.71"
46+
anyhow.workspace = true
4647
chrono = { version = "0.4.24", default-features = false, features = ["clock"] }
4748
clap = { version = "4.3.12", features = ["cargo", "wrap_help"] }
4849
clap_complete = "4.3.2"

crates/mdbook-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ repository.workspace = true
88
rust-version.workspace = true
99

1010
[dependencies]
11+
anyhow.workspace = true
1112

1213
[lints]
1314
workspace = true

crates/mdbook-core/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@
55
/// This is provided as a way for custom preprocessors and renderers to do
66
/// compatibility checks.
77
pub const MDBOOK_VERSION: &str = env!("CARGO_PKG_VERSION");
8+
9+
/// The error types used in mdbook.
10+
pub mod errors {
11+
pub use anyhow::{Error, Result};
12+
}

examples/nop-preprocessor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! A basic example of a preprocessor that does nothing.
22
33
use crate::nop_lib::Nop;
4+
use anyhow::Error;
45
use clap::{Arg, ArgMatches, Command};
56
use mdbook::book::Book;
6-
use mdbook::errors::Error;
77
use mdbook::preprocess::{CmdPreprocessor, Preprocessor, PreprocessorContext};
88
use semver::{Version, VersionReq};
99
use std::io;

examples/remove-emphasis/mdbook-remove-emphasis/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.1.0"
44
edition.workspace = true
55

66
[dependencies]
7+
anyhow.workspace = true
78
mdbook = { path = "../../.." }
89
pulldown-cmark = { version = "0.12.2", default-features = false }
910
pulldown-cmark-to-cmark = "18.0.0"

examples/remove-emphasis/mdbook-remove-emphasis/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! This is a demonstration of an mdBook preprocessor which parses markdown
22
//! and removes any instances of emphasis.
33
4+
use anyhow::Error;
45
use mdbook::BookItem;
56
use mdbook::book::{Book, Chapter};
6-
use mdbook::errors::Error;
77
use mdbook::preprocess::{CmdPreprocessor, Preprocessor, PreprocessorContext};
88
use pulldown_cmark::{Event, Parser, Tag, TagEnd};
99
use std::io;

src/book/book.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use std::path::{Path, PathBuf};
66

77
use super::summary::{Link, SectionNumber, Summary, SummaryItem, parse_summary};
88
use crate::config::BuildConfig;
9-
use crate::errors::*;
109
use crate::utils::bracket_escape;
10+
use anyhow::{Context, Result};
1111
use log::debug;
1212
use serde::{Deserialize, Serialize};
1313

src/book/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use std::path::PathBuf;
44

55
use super::MDBook;
66
use crate::config::Config;
7-
use crate::errors::*;
87
use crate::theme;
98
use crate::utils::fs::write_file;
9+
use anyhow::{Context, Result};
1010
use log::{debug, error, info, trace};
1111

1212
/// A helper for setting up a new book and its directory structure.

src/book/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub use self::book::{Book, BookItem, BookItems, Chapter, load_book};
1313
pub use self::init::BookBuilder;
1414
pub use self::summary::{Link, SectionNumber, Summary, SummaryItem, parse_summary};
1515

16+
use anyhow::{Context, Error, Result, bail};
1617
use log::{debug, error, info, log_enabled, trace, warn};
1718
use std::ffi::OsString;
1819
use std::io::{IsTerminal, Write};
@@ -22,7 +23,6 @@ use tempfile::Builder as TempFileBuilder;
2223
use toml::Value;
2324
use topological_sort::TopologicalSort;
2425

25-
use crate::errors::*;
2626
use crate::preprocess::{
2727
CmdPreprocessor, IndexPreprocessor, LinkPreprocessor, Preprocessor, PreprocessorContext,
2828
};

0 commit comments

Comments
 (0)