File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change 1- use eyre:: bail;
1+ use eyre:: { ContextCompat , bail} ;
22use serde:: { Deserialize , Serialize } ;
33use toml:: value:: Date ;
44
@@ -21,12 +21,12 @@ pub struct FrontMatter {
2121/// the tuple.
2222pub fn parse ( markdown : & str ) -> eyre:: Result < ( FrontMatter , & str ) > {
2323 if !markdown. starts_with ( "+++\n " ) {
24- bail ! ( "markdown file must start with the line ` +++` " ) ;
24+ bail ! ( "missing start of TOML front matter ( +++) " ) ;
2525 }
2626 let ( front_matter, content) = markdown
2727 . trim_start_matches ( "+++\n " )
2828 . split_once ( "\n +++\n " )
29- . expect ( "couldn't find the end of the front matter: ` +++`" ) ;
29+ . context ( "missing end of TOML front matter ( +++)" ) ? ;
3030
3131 Ok ( ( toml:: from_str ( front_matter) ?, content) )
3232}
@@ -63,7 +63,9 @@ mod tests {
6363
6464 for post in posts {
6565 let content = fs:: read_to_string ( & post) . unwrap ( ) ;
66- let normalized = normalize ( & content) . unwrap ( ) ;
66+ let normalized = normalize ( & content) . unwrap_or_else ( |err| {
67+ panic ! ( "failed to normalize {:?}: {err}" , post. file_name( ) . unwrap( ) ) ;
68+ } ) ;
6769
6870 if content != normalized {
6971 if env:: var ( "FIX_FRONT_MATTER" ) . is_ok ( ) {
Original file line number Diff line number Diff line change 11use super :: blogs:: Manifest ;
2+ use eyre:: Context ;
23use front_matter:: FrontMatter ;
34use regex:: Regex ;
45use serde:: Serialize ;
@@ -56,7 +57,8 @@ impl Post {
5657 ..
5758 } ,
5859 contents,
59- ) = front_matter:: parse ( & contents) ?;
60+ ) = front_matter:: parse ( & contents)
61+ . with_context ( || format ! ( "failed to parse {filename}" ) ) ?;
6062
6163 let options = comrak:: Options {
6264 render : comrak:: RenderOptions :: builder ( ) . unsafe_ ( true ) . build ( ) ,
You can’t perform that action at this time.
0 commit comments