@@ -211,12 +211,18 @@ def _parse_doc_item(
211211 f"'{ item_key } ' and '{ other_key } ' @ '{ toc_path } { items_key } /{ item_idx } '"
212212 )
213213
214- if link_keys == {FILE_KEY }:
215- items .append (FileItem (item_data [FILE_KEY ]))
216- elif link_keys == {GLOB_KEY }:
217- items .append (GlobItem (item_data [GLOB_KEY ]))
218- elif link_keys == {URL_KEY }:
219- items .append (UrlItem (item_data [URL_KEY ], item_data .get ("title" )))
214+ try :
215+ if link_keys == {FILE_KEY }:
216+ items .append (FileItem (item_data [FILE_KEY ]))
217+ elif link_keys == {GLOB_KEY }:
218+ items .append (GlobItem (item_data [GLOB_KEY ]))
219+ elif link_keys == {URL_KEY }:
220+ items .append (UrlItem (item_data [URL_KEY ], item_data .get ("title" )))
221+ except (ValueError , TypeError ) as exc :
222+ exc_arg = exc .args [0 ] if exc .args else ""
223+ raise MalformedError (
224+ f"item validation @ '{ toc_path } { items_key } /{ item_idx } ': { exc_arg } "
225+ ) from exc
220226
221227 # generate toc key-word arguments
222228 keywords = {k : toc_data [k ] for k in TOCTREE_OPTIONS if k in toc_data }
@@ -226,16 +232,20 @@ def _parse_doc_item(
226232
227233 try :
228234 toc_item = TocTree (items = items , ** keywords )
229- except TypeError as exc :
230- raise MalformedError (f"toctree validation @ '{ toc_path } '" ) from exc
235+ except (ValueError , TypeError ) as exc :
236+ exc_arg = exc .args [0 ] if exc .args else ""
237+ raise MalformedError (
238+ f"toctree validation @ '{ toc_path } ': { exc_arg } "
239+ ) from exc
231240 toctrees .append (toc_item )
232241
233242 try :
234243 doc_item = Document (
235244 docname = data [file_key ], title = data .get ("title" ), subtrees = toctrees
236245 )
237- except TypeError as exc :
238- raise MalformedError (f"doc validation: { path } " ) from exc
246+ except (ValueError , TypeError ) as exc :
247+ exc_arg = exc .args [0 ] if exc .args else ""
248+ raise MalformedError (f"doc validation @ '{ path } ': { exc_arg } " ) from exc
239249
240250 # list of docs that need to be parsed recursively (and path)
241251 docs_to_be_parsed_list = [
0 commit comments