66import os
77
88from foliant .preprocessors .utils .preprocessor_ext import BasePreprocessorExt
9+ from foliant .utils import output
910
1011
1112class Preprocessor (BasePreprocessorExt ):
1213 defaults = {
1314 'not_in_chapters' : [],
15+ 'strict_check' : True ,
1416 }
1517
1618 def __init__ (self , * args , ** kwargs ):
@@ -20,6 +22,7 @@ def __init__(self, *args, **kwargs):
2022
2123 self .logger .debug (f'Preprocessor inited: { self .__dict__ } ' )
2224 self .src_dir = self .project_path / self .config ['src_dir' ]
25+ self .critical_error = []
2326
2427 def apply (self ):
2528 self .logger .info ('Applying preprocessor' )
@@ -43,7 +46,13 @@ def _recursive_process_chapters(chapters_subset):
4346 self .logger .debug (f'Adding file to the list of mentioned in chapters: { chapter_file_path } ' )
4447 else :
4548 self .logger .debug ('Not exist, throw warning' )
46- self ._warning (f'{ os .path .relpath (chapter_file_path )} does not exist' )
49+ msg = f'{ os .path .relpath (chapter_file_path )} does not exist'
50+ if self .options ['strict_check' ]:
51+ self .logger .error (msg )
52+ self .critical_error .append (msg )
53+ output (f'ERROR: { msg } ' )
54+ else :
55+ self ._warning (msg )
4756
4857 chapters_files_paths .append (chapter_file_path )
4958
@@ -82,5 +91,10 @@ def _fill_not_in_chapters():
8291 else :
8392 self .logger .debug ('Not mentioned, throw warning' )
8493 self ._warning (f'{ os .path .relpath (markdown_file_path )} does not mentioned in chapters' )
85-
86- self .logger .info ('Preprocessor applied' )
94+ if len (self .critical_error ) > 0 :
95+ self .logger .info ('Critical errors have occurred' )
96+ errors = '\n ' .join (self .critical_error )
97+ output (f'\n Build failed: checksources preprocessor errors: \n { errors } \n ' )
98+ os ._exit (2 )
99+ else :
100+ self .logger .info ('Preprocessor applied' )
0 commit comments