@@ -369,11 +369,19 @@ def _is_existing_ledger_entry(self, section_title: str) -> bool:
369369 entry_name = match .group (1 )
370370 return self ._is_existing_ledger_entry_name (entry_name )
371371
372- def _url_exists (self , url : str ) -> bool :
372+ def _url_exists (self , url : str , safe_on_error : bool = True ) -> bool :
373373 """Check if a URL exists by making a HEAD request.
374374
375- Returns True if the URL returns 200, False if 404.
376- On network errors, returns True to be safe (assume it exists).
375+ Args:
376+ url: The URL to check
377+ safe_on_error: If True, return True on network errors (assume
378+ resource exists to avoid false positives). If False, return
379+ False on network errors (used for heuristic checks where
380+ false positives are worse than false negatives).
381+
382+ Returns:
383+ True if the URL returns 200, False if 404 or on error when
384+ safe_on_error is False.
377385 """
378386 try :
379387 req = urllib .request .Request (url , method = "HEAD" )
@@ -383,21 +391,23 @@ def _url_exists(self, url: str) -> bool:
383391 # 404 means the resource doesn't exist
384392 if e .code == 404 :
385393 return False
386- # Other errors (500, etc.) - assume it exists to be safe
394+ # Other errors (500, etc.)
387395 print (f"Warning: unexpected error checking { url } : { e } " )
388- return True
396+ return safe_on_error
389397 except (urllib .error .URLError , TimeoutError ) as e :
390- # Network error - assume it exists to be safe
398+ # Network error
391399 print (f"Warning: network error checking { url } : { e } " )
392- return True
400+ return safe_on_error
393401
394- def _is_existing_ledger_entry_name (self , entry_name : str ) -> bool :
402+ def _is_existing_ledger_entry_name (
403+ self , entry_name : str , safe_on_error : bool = True
404+ ) -> bool :
395405 """Check if the given ledger entry name exists on xrpl.org."""
396406 url = (
397407 "https://xrpl.org/docs/references/protocol/"
398408 f"ledger-data/ledger-entry-types/{ entry_name .lower ()} "
399409 )
400- return self ._url_exists (url )
410+ return self ._url_exists (url , safe_on_error )
401411
402412 def _is_existing_transaction (self , section_title : str ) -> bool :
403413 """Check if a Transaction section is for an existing transaction.
@@ -410,13 +420,15 @@ def _is_existing_transaction(self, section_title: str) -> bool:
410420 return False
411421 return self ._is_existing_transaction_name (match .group (1 ))
412422
413- def _is_existing_transaction_name (self , transaction_name : str ) -> bool :
423+ def _is_existing_transaction_name (
424+ self , transaction_name : str , safe_on_error : bool = True
425+ ) -> bool :
414426 """Check if the given transaction name exists on xrpl.org."""
415427 url = (
416428 "https://xrpl.org/docs/references/protocol/transactions/types/"
417429 f"{ transaction_name .lower ()} "
418430 )
419- return self ._url_exists (url )
431+ return self ._url_exists (url , safe_on_error )
420432
421433 def _find_existing_transaction_like_headings (self ) -> List [Section ]:
422434 """Find headings that look like "`SomeTransaction` Transaction".
@@ -447,8 +459,10 @@ def _find_existing_transaction_like_headings(self) -> List[Section]:
447459 candidate_name = match .group (1 )
448460
449461 # Only treat this as a signal if the candidate resolves to a
450- # known XRPL transaction type.
451- if self ._is_existing_transaction_name (candidate_name ):
462+ # known XRPL transaction type. Use safe_on_error=False to avoid
463+ # false positives on network errors (better to miss a warning
464+ # than to incorrectly fail validation).
465+ if self ._is_existing_transaction_name (candidate_name , False ):
452466 matches .append (section )
453467
454468 return matches
@@ -484,8 +498,9 @@ def _find_existing_ledger_entry_like_headings(self) -> List[Section]:
484498 candidate_name = match .group (1 )
485499
486500 # Only treat this as a signal if the candidate resolves to a
487- # known XRPL ledger entry type.
488- if self ._is_existing_ledger_entry_name (candidate_name ):
501+ # known XRPL ledger entry type. Use safe_on_error=False to avoid
502+ # false positives on network errors.
503+ if self ._is_existing_ledger_entry_name (candidate_name , False ):
489504 matches .append (section )
490505
491506 return matches
0 commit comments