Skip to content

Commit

Permalink
Handle empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
ColeDCrawford committed May 28, 2024
1 parent 53d3a32 commit ab6c413
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions edtf/parser/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,20 +343,22 @@ def f(toks):
)


def parse_edtf(str, parseAll=True, fail_silently=False, debug=None):
def parse_edtf(input_string, parseAll=True, fail_silently=False, debug=None):
if debug is None:
debug = DEBUG_PYPARSING
try:
if not str:
if not input_string:
raise ParseException("You must supply some input text")
p = edtfParser.parseString(str.strip(), parseAll)
p = edtfParser.parseString(input_string.strip(), parseAll)
if p:
return p[0]
except ParseException as err:
if fail_silently:
return None
if debug:
raise
near_text = str[max(err.loc - 10, 0) : err.loc + 10]
near_text = ""
if input_string:
near_text = input_string[max(err.loc - 10, 0) : err.loc + 10]
full_msg = f"Error at position {err.loc}: Invalid input or format near '{near_text}'. Please provide a valid EDTF string."
raise EDTFParseException(full_msg) from None

0 comments on commit ab6c413

Please sign in to comment.