Fixed error reporting in REPL

This commit is contained in:
Mattia Giambirtone 2022-12-04 17:02:32 +01:00
parent 21738b9382
commit 15ec8dce54
1 changed files with 6 additions and 3 deletions

View File

@ -42,10 +42,13 @@ proc print*(exc: CompileError) =
## Prints a formatted error message
## for compilation errors to stderr
var file = exc.file
if file notin ["<string>", ""]:
var contents: string
if file notin ["<string>", "", "stdin"]:
file = relativePath(exc.file, getCurrentDir())
printError(file, readFile(file).splitLines()[exc.line - 1].strip(chars={'\n'}),
exc.line, exc.node.getRelativeBoundaries(), exc.function,
contents = readFile(file).splitLines()[exc.line - 1].strip(chars={'\n'})
else:
contents = ""
printError(file, contents, exc.line, exc.node.getRelativeBoundaries(), exc.function,
exc.msg)