Skip to content

Commit

Permalink
Creation of helper function for formating error parsing output
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Daniel Bennett committed Oct 5, 2020
1 parent 429213f commit 5adb328
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions api/ECNQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,12 @@ def __parseSections(self) -> list:

# Checks for nesteded delimiters within the reply from user
elif replyFromUserDelimiter == True and (line.startswith("===") or line.startswith("***")) and not line.startswith("===="):

parseErrorMessage = ("Nested delimiter encountered on line "
+ str(lineNumber) + ":\n"
+ "\t " + line)

# Creates a dictionary with information regarding to the nested delimiter
errorDictionary = {
"type": "parseError",
"datetime": self.__getFormattedDate(str(datetime.datetime.now())),
"content": parseErrorMessage
}
columnNum = 0

errorMessage = "Nested delimiter encountered"

errorDictionary = self.__errorParsing(line, lineNumber, columnNum, errorMessage)

# Appends the error dictionary to sections
sections.append(errorDictionary)
Expand Down Expand Up @@ -622,8 +617,10 @@ def __userReplyParsing(self, replyContent: list) -> dict:
elif line.startswith("Date: "):

# Matches everything after "Date: "
dateStr = (re.search("(?<=Date: )(.*)", line)).group()

try:
dateStr = (re.search("(?<=Date: )(.*)", line)).group()
except:
dateStr = ""
# Formatts the date to UTC
formattedDateTime = self.__getFormattedDate(dateStr)

Expand Down Expand Up @@ -705,6 +702,34 @@ def __getFormattedMessageContent(self, messageContent: list) -> list:

return messageContent

def __errorParsing(self, line: str, lineNum: int, lineColumn: int, errorMessage: str) -> dict:
"""Returns a dictionary with error parse information
Returns:
{
dictionary: "type": "parse_error",
datetime: time_of_execution,
content: [
'expected value item_row_num:item_column_num',
'current line in item'
]
}
"""

errorDictionary = {
"type": "parse_error",
"datetime": self.__getFormattedDate(str(datetime.datetime.now())),
"content": []
}

# Error message with line and column numbers
errorMessage = errorMessage + " at " + str(lineNum) + ":" + str(lineColumn)

errorDictionary["content"].append(errorMessage)

errorDictionary["content"].append(line)

return errorDictionary

def __isLocked(self) -> Union[str, bool]:
"""Returns a string info about the lock if true and a bool False if false
Expand Down

0 comments on commit 5adb328

Please sign in to comment.