@@ -3,6 +3,12 @@ use std::path::PathBuf;
33#[ cfg( feature = "biblatex" ) ]
44pub use biblatex_module:: * ;
55
6+ /// Used once before all but the 1st errors.
7+ const TOP_INDENT : & str = "\n Caused by:" ;
8+
9+ /// Used to indent next error.
10+ const INDENT : & str = " " ;
11+
612/// The main error that is handled in the `main()` function.
713#[ derive( thiserror:: Error , Debug ) ]
814pub enum Error {
@@ -11,10 +17,10 @@ pub enum Error {
1117 BibliographyError ( #[ from] BibliographyError ) ,
1218 /// Invalid Bib(La)TeX input file format.
1319 #[ cfg( feature = "biblatex" ) ]
14- #[ error( "Invalid format: expected Bib(La)TeX\n Caused by: \n \t {0:? }" ) ]
20+ #[ error( "Invalid format: expected Bib(La)TeX\n {TOP_INDENT} \n {INDENT}{0 }" ) ]
1521 InvalidBiblatex ( #[ from] BibLaTeXErrors ) ,
1622 /// Invalid YAML input file format.
17- #[ error( "Invalid format: expected YAML\n Caused by: \n \t {0:? }" ) ]
23+ #[ error( "Invalid format: expected YAML\n {TOP_INDENT} \n {INDENT}{0 }" ) ]
1824 InvalidYaml ( #[ from] serde_yaml:: Error ) ,
1925 /// Other error.
2026 #[ error( "{0}" ) ]
@@ -25,13 +31,13 @@ pub enum Error {
2531#[ derive( thiserror:: Error , Debug ) ]
2632pub enum BibliographyError {
2733 /// Bibliography file not found.
28- #[ error( "Bibliography file {0:?} not found." ) ]
34+ #[ error( r# "Bibliography file "{0}" not found."# ) ]
2935 NotFound ( PathBuf ) ,
3036 /// Error while reading the bibliography file (with OS error code).
31- #[ error( "Error while reading the bibliography file {0:?} : {1}" ) ]
37+ #[ error( r# "Error while reading the bibliography file "{0}" : {1}"# ) ]
3238 ReadErrorWithCode ( PathBuf , i32 ) ,
3339 /// Error while reading the bibliography file.
34- #[ error( "Error while reading the bibliography file {0:?}." ) ]
40+ #[ error( r# "Error while reading the bibliography file "{0}"."# ) ]
3541 ReadError ( PathBuf ) ,
3642}
3743
@@ -43,37 +49,31 @@ impl From<&str> for Error {
4349
4450#[ cfg( feature = "biblatex" ) ]
4551mod biblatex_module {
46- use std:: { error:: Error , fmt:: Display } ;
52+ use super :: INDENT ;
53+ use std:: fmt:: { Display , Formatter , Result } ;
4754
4855 /// Errors that may occur when parsing a BibLaTeX file.
4956 #[ derive( thiserror:: Error , Clone , Debug ) ]
5057 pub enum BibLaTeXError {
5158 /// An error occurred when parsing a BibLaTeX file.
59+ #[ error( "BibLaTeX parse error\n {INDENT}{0}" ) ]
5260 Parse ( biblatex:: ParseError ) ,
5361 /// One of the BibLaTeX fields was malformed for its type.
62+ #[ error( "BibLaTeX type error\n {INDENT}{0}" ) ]
5463 Type ( biblatex:: TypeError ) ,
5564 }
5665
57- impl Display for BibLaTeXError {
58- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
59- match self {
60- Self :: Parse ( err) => write ! ( f, "biblatex parse error: {}" , err) ,
61- Self :: Type ( err) => write ! ( f, "biblatex type error: {}" , err) ,
62- }
63- }
64- }
65-
6666 /// Wrapper over an array of `BibLaTeXError` elements.
6767 #[ derive( thiserror:: Error , Clone , Debug ) ]
6868 pub struct BibLaTeXErrors ( pub Vec < BibLaTeXError > ) ;
6969
7070 impl Display for BibLaTeXErrors {
71- fn fmt ( & self , f : & mut std :: fmt :: Formatter < ' _ > ) -> std :: fmt :: Result {
71+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> Result {
7272 let sources = self
7373 . 0
7474 . clone ( )
7575 . into_iter ( )
76- . filter_map ( |x| x. source ( ) . map ( |err| format ! ( "{err:?}" ) ) )
76+ . map ( |x| x. to_string ( ) )
7777 . collect :: < Vec < String > > ( )
7878 . join ( "\n \t " ) ;
7979 write ! ( f, "{sources}" )
0 commit comments