@@ -614,9 +614,12 @@ def on_post_build(self, config, **kwargs):
614614 #modify search_index in the style of mkdocs-exclude-search
615615 if self .setup ['search_plugin_found' ] and self .config ['search_index' ] != 'clear' :
616616 search_index_filename = Path (config .data ["site_dir" ] + "/search/search_index.json" )
617- #TODO: Check if search_index.json exists and error if not found (moved its location)
618- with open (search_index_filename , "r" ) as f :
619- search_entries = json .load (f )
617+ try :
618+ with open (search_index_filename , "r" ) as f :
619+ search_entries = json .load (f )
620+ except :
621+ logger .error ('Search index needs modification, but could not read "search_index.json"!' )
622+ os ._exit (1 )
620623
621624 for entry in search_entries ['docs' ].copy (): #iterate through all entries of search_index
622625 for location in self .setup ['locations' ].keys ():
@@ -637,8 +640,12 @@ def on_post_build(self, config, **kwargs):
637640 entry ['location' ] = location + ';' + b';' .join (code ).decode ('ascii' )
638641 break
639642
640- with open (search_index_filename , "w" ) as f :
641- json .dump (search_entries , f )
643+ try :
644+ with open (search_index_filename , "w" ) as f :
645+ json .dump (search_entries , f )
646+ except :
647+ logger .error ('Search index needs modification, but could not write "search_index.json"!' )
648+ os ._exit (1 )
642649 logger .info ('Modified search_index.' )
643650
644651 # optionally download cryptojs
0 commit comments