diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-23 15:25:23 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-23 15:25:43 -0700 |
| commit | 0ee80c555d9e136143c50fb9bdc6372912909fc6 (patch) | |
| tree | a020f842f654b1ecccaf23475e33843cd5b831c9 | |
| parent | 09d797eddcf850489fbede88283420fff3a5a293 (diff) | |
Fixing a bug in error handling.
| -rw-r--r-- | error_handling.moon | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/error_handling.moon b/error_handling.moon index f28a8c8..5a5dd02 100644 --- a/error_handling.moon +++ b/error_handling.moon @@ -68,15 +68,18 @@ print_error = (error_message, start_fn, stop_fn)-> filename,start,stop = calling_fn.source\match('@([^[]*)%[([0-9]+):([0-9]+)]') assert(filename) file = files.read(filename) - err_line = files.get_line(file, calling_fn.currentline) - offending_statement = colored.bright(colored.red(err_line\match("^[ ]*(.*)"))) -- TODO: get name properly name = if calling_fn.name if tmp = calling_fn.name\match("^A_([a-zA-Z0-9_]*)$") "action '#{tmp\gsub("_"," ")\gsub("x([0-9A-F][0-9A-F])", => string.char(tonumber(@, 16)))}'" else "action '#{calling_fn.name}'" else "main chunk" - line = colored.yellow("#{filename}:#{calling_fn.currentline} in #{name}\n #{offending_statement}") + + if err_line = files.get_line(file, calling_fn.currentline) + offending_statement = colored.bright(colored.red(err_line\match("^[ ]*(.*)"))) + line = colored.yellow("#{filename}:#{calling_fn.currentline} in #{name}\n #{offending_statement}") + else + line = colored.yellow("#{filename}:#{calling_fn.currentline} in #{name}") else ok, file = pcall ->files.read(calling_fn.short_src) if not ok then file = nil @@ -117,9 +120,9 @@ print_error = (error_message, start_fn, stop_fn)-> line = colored.blue("#{calling_fn.short_src}:#{calling_fn.currentline} in #{name or '?'}") if file - err_line = files.get_line(file, line_num) - offending_statement = colored.bright(colored.red(err_line\match("^[ ]*(.*)$"))) - line ..= "\n "..offending_statement + if err_line = files.get_line(file, line_num) + offending_statement = colored.bright(colored.red(err_line\match("^[ ]*(.*)$"))) + line ..= "\n "..offending_statement io.stderr\write(line,"\n") if calling_fn.istailcall io.stderr\write(" #{colored.dim colored.white " (...tail calls...)"}\n") |
