@@ -282,7 +282,7 @@ object Splicer {
282
282
283
283
val name = getDirectName(fn.info.finalResultType, fn.name.asTermName)
284
284
val method = getMethod(clazz, name, paramsSig(fn))
285
- (args : List [Object ]) => stopIfRuntimeException(method.invoke(inst, args : _* ))
285
+ (args : List [Object ]) => stopIfRuntimeException(method.invoke(inst, args : _* ), method )
286
286
}
287
287
288
288
private def interpretModuleAccess (fn : Symbol )(implicit env : Env ): Object =
@@ -339,7 +339,7 @@ object Splicer {
339
339
340
340
private def extraMsg = " . The most common reason for that is that you apply macros in the compilation run that defines them"
341
341
342
- private def stopIfRuntimeException [T ](thunk : => T ): T = {
342
+ private def stopIfRuntimeException [T ](thunk : => T , method : Method ): T = {
343
343
try thunk
344
344
catch {
345
345
case ex : RuntimeException =>
@@ -352,13 +352,16 @@ object Splicer {
352
352
throw new StopInterpretation (sw.toString, pos)
353
353
case ex : InvocationTargetException =>
354
354
val sw = new StringWriter ()
355
- sw.write(" An exception occurred while executing macro expansion: " )
356
- sw.write(ex.getTargetException.getMessage)
357
- sw.write(" \n " )
358
- for (stack <- ex.getTargetException.getStackTrace.iterator.takeWhile(_.getClassName != this .getClass.getName).drop(1 )) {
359
- sw.write(stack.toString)
360
- sw.write(" \n " )
355
+ sw.write(" Exception occurred while executing macro expansion.\n " )
356
+ val targetException = ex.getTargetException
357
+ if (! ctx.settings.Ydebug .value) {
358
+ val end = targetException.getStackTrace.lastIndexWhere { x =>
359
+ x.getClassName == method.getDeclaringClass.getCanonicalName && x.getMethodName == method.getName
360
+ }
361
+ val shortStackTrace = targetException.getStackTrace.take(end + 1 )
362
+ targetException.setStackTrace(shortStackTrace)
361
363
}
364
+ targetException.printStackTrace(new PrintWriter (sw))
362
365
sw.write(" \n " )
363
366
throw new StopInterpretation (sw.toString, pos)
364
367
}
0 commit comments