@@ -79,21 +79,13 @@ struct MacroExpansionError
7979 ex:: SyntaxTree
8080 msg:: String
8181 position:: Symbol
82- stacktrace:: Vector{Base.StackTraces.StackFrame}
8382end
8483
8584"""
8685`position` - the source position relative to the node - may be `:begin` or `:end` or `:all`
8786"""
8887function MacroExpansionError (ex:: SyntaxTree , msg:: AbstractString ; position= :all )
89- MacroExpansionError (nothing , ex, msg, position, scrub_expand_macro_stacktrace (stacktrace (backtrace ())))
90- end
91-
92- function scrub_expand_macro_stacktrace (stacktrace:: Vector{Base.StackTraces.StackFrame} )
93- idx = @something findfirst (stacktrace) do stackframe:: Base.StackTraces.StackFrame
94- stackframe. func === :expand_macro && stackframe. file === Symbol (@__FILE__ )
95- end error (" `scrub_expand_macro_stacktrace` is expected to be called from `expand_macro`" )
96- return stacktrace[1 : idx- 1 ]
88+ MacroExpansionError (nothing , ex, msg, position)
9789end
9890
9991function Base. showerror (io:: IO , exc:: MacroExpansionError )
@@ -156,12 +148,13 @@ function expand_macro(ctx::MacroExpansionContext, ex::SyntaxTree)
156148 # TODO : Allow invoking old-style macros for compat
157149 invokelatest (macfunc, macro_args... )
158150 catch exc
151+ # TODO : Using rethrow() is kinda ugh. Is there a way to avoid it?
152+ # NOTE: Although currently rethrow() is necessary to allow outside catchers to access full stacktrace information
159153 if exc isa MacroExpansionError
160154 # Add context to the error.
161- # TODO : Using rethrow() is kinda ugh. Is there a way to avoid it?
162- rethrow (MacroExpansionError (mctx, exc. ex, exc. msg, exc. position, exc. stacktrace))
155+ rethrow (MacroExpansionError (mctx, exc. ex, exc. msg, exc. position))
163156 else
164- throw (MacroExpansionError (mctx, ex, " Error expanding macro" , :all , scrub_expand_macro_stacktrace ( stacktrace ( catch_backtrace ())) ))
157+ rethrow (MacroExpansionError (mctx, ex, " Error expanding macro" , :all ))
165158 end
166159 end
167160
0 commit comments