initial commit
This commit is contained in:
23
error.py
Normal file
23
error.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from console import console
|
||||
|
||||
|
||||
def traceback(code: str, error_type: str, error_message: str, line: int | None = None, start_column: int | None = None, end_column: int | None = None):
|
||||
if line != None:
|
||||
console.print(f"[bold red]{error_type} on line {line}: [/]{error_message}\n")
|
||||
lines = code.split("\n")[line-1:line+2]
|
||||
|
||||
console.print(f"{line } > " + lines[0], highlight=False)
|
||||
if start_column != None and end_column != None:
|
||||
console.print(" " + (" " * start_column) + "[bold red]" + ("^" * (end_column-start_column+1)))
|
||||
|
||||
try:
|
||||
console.print(f"{line+1} " + lines[1], highlight=False)
|
||||
console.print(f"{line+2} " + lines[2], highlight=False)
|
||||
console.print(" ...", highlight=False)
|
||||
except IndexError: # the file is less than 3 lines i guess
|
||||
pass
|
||||
else:
|
||||
console.print(f"[bold red]{error_type}: {error_message}")
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user