Skip to content

Commit

Permalink
Helpful error when macro return has no location
Browse files Browse the repository at this point in the history
It would previously crash due to trying to access .location.start when
.location was undefined.
  • Loading branch information
anko committed Jan 16, 2020
1 parent c456628 commit 84d848b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/compile.ls
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,17 @@ list-to-estree = (env, { values }:ast, options={}) ->
try
macro-return := that.apply local-env, rest
catch e
# Prepend information to the error's message about the macro it came
# from, to help in debugging. Then re-throw it.

# Prepend data to the error message to help in debugging.
explanation = "Error evaluating macro `#{head.value}`"

{ line, column } = ast.location.start
e.message = "Error evaluating macro `#{head.value}` \
(called at line #line, column #column): #{e.message}"
if ast.location
{ line, column } = ast.location.start
explanation += " (called at line #line, column #column)"
else
explanation += " (called at unknown location; likely returned from a macro)"
e.message = "#explanation: #{e.message}"
throw e

switch typeof! macro-return
Expand Down

0 comments on commit 84d848b

Please sign in to comment.