Skip to content

Commit

Permalink
chore(build): better error displaying
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Dec 18, 2024
1 parent 9624a86 commit 8ae4b98
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
17 changes: 16 additions & 1 deletion crates/rari-doc/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use std::path::PathBuf;

use chrono::NaiveDateTime;
use itertools::Itertools;
use rari_types::globals::{base_url, build_out_root, git_history};
use rari_types::globals::{
base_url, blog_root, build_out_root, contributor_spotlight_root, curriculum_root,
generic_content_root, git_history,
};
use rari_types::locale::{default_locale, Locale};
use rayon::iter::{IntoParallelIterator, ParallelIterator};
use sha2::{Digest, Sha256};
Expand Down Expand Up @@ -187,6 +190,9 @@ pub fn build_top_level_meta(locale_meta: Vec<JsonDocMetadata>) -> Result<(), Doc
/// This function will return an error if:
/// - An error occurs while building any of the curriculum pages.
pub fn build_curriculum_pages<'a>() -> Result<Vec<SitemapMeta<'a>>, DocError> {
if curriculum_root().is_none() {
return Err(DocError::NoCurriculumRoot);
}
curriculum_files()
.by_path
.values()
Expand Down Expand Up @@ -241,6 +247,9 @@ fn copy_blog_author_avatars() -> Result<(), DocError> {
/// - An error occurs while copying blog author avatars.
/// - An error occurs while building any of the blog pages.
pub fn build_blog_pages<'a>() -> Result<Vec<SitemapMeta<'a>>, DocError> {
if blog_root().is_none() {
return Err(DocError::NoBlogRoot);
}
copy_blog_author_avatars()?;

let rss_file = build_out_root()?
Expand Down Expand Up @@ -292,6 +301,9 @@ pub fn build_blog_pages<'a>() -> Result<Vec<SitemapMeta<'a>>, DocError> {
/// This function will return an error if:
/// - An error occurs while building any of the generic pages.
pub fn build_generic_pages<'a>() -> Result<Vec<SitemapMeta<'a>>, DocError> {
if generic_content_root().is_none() {
return Err(DocError::NoGenericContentRoot);
}
generic_content_files()
.values()
.map(|page| {
Expand Down Expand Up @@ -320,6 +332,9 @@ pub fn build_generic_pages<'a>() -> Result<Vec<SitemapMeta<'a>>, DocError> {
/// This function will return an error if:
/// - An error occurs while building any of the contributor spotlight pages.
pub fn build_contributor_spotlight_pages<'a>() -> Result<Vec<SitemapMeta<'a>>, DocError> {
if contributor_spotlight_root().is_none() {
return Err(DocError::NoContributorSpotlightRoot);
}
contributor_spotlight_files()
.values()
.map(|page| {
Expand Down
22 changes: 11 additions & 11 deletions crates/rari-doc/src/cached_readers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use rari_types::locale::Locale;
use rari_utils::concat_strs;
use rari_utils::io::read_to_string;
use serde::{Deserialize, Serialize};
use tracing::error;
use tracing::{error, warn};

use crate::contributors::{WikiHistories, WikiHistory};
use crate::error::DocError;
Expand Down Expand Up @@ -319,7 +319,7 @@ fn gather_curriculum() -> Result<CurriculumFiles, DocError> {
}
}

fn gather_contributre_spotlight() -> Result<HashMap<String, Page>, DocError> {
fn gather_contributor_spotlight() -> Result<HashMap<String, Page>, DocError> {
if let Some(root) = contributor_spotlight_root() {
Ok(read_docs_parallel::<ContributorSpotlight>(&[root], None)?
.into_iter()
Expand All @@ -339,7 +339,7 @@ fn gather_contributre_spotlight() -> Result<HashMap<String, Page>, DocError> {
.map(|page| (page.url().to_ascii_lowercase(), page))
.collect())
} else {
Err(DocError::NoGenericContentRoot)
Err(DocError::NoContributorSpotlightRoot)
}
}

Expand All @@ -357,14 +357,14 @@ pub fn curriculum_files() -> Cow<'static, CurriculumFiles> {
if cache_content() {
Cow::Borrowed(CACHED_CURRICULUM.get_or_init(|| {
gather_curriculum()
.map_err(|e| error!("{e}"))
.inspect_err(|e| warn!("{e}"))
.ok()
.unwrap_or_default()
}))
} else {
Cow::Owned(
gather_curriculum()
.map_err(|e| error!("{e}"))
.inspect_err(|e| warn!("{e}"))
.unwrap_or_default(),
)
}
Expand Down Expand Up @@ -409,11 +409,11 @@ fn gather_blog_authors() -> Result<HashMap<String, Arc<Author>>, DocError> {
pub fn blog_files() -> Cow<'static, BlogFiles> {
fn gather() -> BlogFiles {
let posts = gather_blog_posts().unwrap_or_else(|e| {
error!("{e}");
warn!("{e}");
Default::default()
});
let authors = gather_blog_authors().unwrap_or_else(|e| {
error!("{e}");
warn!("{e}");
Default::default()
});
let mut sorted_meta = posts
Expand Down Expand Up @@ -578,7 +578,7 @@ fn read_generic_content_config() -> Result<GenericContentConfig, DocError> {
pub fn generic_content_config() -> Cow<'static, GenericContentConfig> {
fn gather() -> GenericContentConfig {
read_generic_content_config().unwrap_or_else(|e| {
error!("{e}");
warn!("{e}");
Default::default()
})
}
Expand All @@ -603,7 +603,7 @@ pub fn generic_content_config() -> Cow<'static, GenericContentConfig> {
pub fn generic_content_files() -> Cow<'static, UrlToPageMap> {
fn gather() -> UrlToPageMap {
gather_generic_content().unwrap_or_else(|e| {
error!("{e}");
warn!("{e}");
Default::default()
})
}
Expand All @@ -627,8 +627,8 @@ pub fn generic_content_files() -> Cow<'static, UrlToPageMap> {
/// if caching is enabled. Otherwise, returns a `Cow::Owned` containing the read-in contributor spotlight pages.
pub fn contributor_spotlight_files() -> Cow<'static, UrlToPageMap> {
fn gather() -> UrlToPageMap {
gather_contributre_spotlight().unwrap_or_else(|e| {
error!("{e}");
gather_contributor_spotlight().unwrap_or_else(|e| {
warn!("{e}");
Default::default()
})
}
Expand Down
2 changes: 2 additions & 0 deletions crates/rari-doc/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub enum DocError {
NoCurriculumRoot,
#[error("No generic content root set")]
NoGenericContentRoot,
#[error("No contributor spotlights root set")]
NoContributorSpotlightRoot,
#[error("No generic content config found")]
NoGenericContentConfig,
#[error("No H1 found")]
Expand Down

0 comments on commit 8ae4b98

Please sign in to comment.