Skip to content

Commit

Permalink
Improve error reporting format
Browse files Browse the repository at this point in the history
Now it points location with character-level accuracy (instead of
line-level).
  • Loading branch information
jmi2k committed Jun 13, 2020
1 parent c57289a commit 2459a4e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 5 additions & 4 deletions learnbot_dsl/learnbotCode/LearnBlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,16 +923,17 @@ def textCodeToPython(self, name_Client):
def formatError(error):
level = error['level']
message = error['message']
start, end = error['span']
start = error['from']
end = error['to']

if (start == None and end == None):
spanMsg = "somewhere"
elif (end == None):
spanMsg = f"from line {start}"
spanMsg = f"from {start[0]}:{start[1]}"
elif (start == end):
spanMsg = f"line {start}"
spanMsg = f"at {start[0]}:{start[1]}"
else:
spanMsg = f"lines {start}-{end}"
spanMsg = f"from {start[0]}:{start[1]} to {end[0]}{end[1]}"

return f"{level}: {message} ({spanMsg})"

Expand Down
6 changes: 4 additions & 2 deletions learnbot_dsl/learnbotCode/Parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,8 @@ def parserLearntBotCode(inputFile, outputFile, client_name):
errors.append({
'level': 'error',
'message': "Parse error",
'span': (output.lineno, None),
'from': (output.lineno, output.col),
'to': None,
})

return None, errors
Expand All @@ -908,7 +909,8 @@ def parserLearntBotCodeFromCode(code, name_client):
errors.append({
'level': 'error',
'message': "Parse error",
'span': (output.lineno, None),
'from': (output.lineno, output.col),
'to': None,
})

return None, errors
Expand Down

0 comments on commit 2459a4e

Please sign in to comment.