@@ -282,7 +282,7 @@ object Splicer {
282282
283283 val name = getDirectName(fn.info.finalResultType, fn.name.asTermName)
284284 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 )
286286 }
287287
288288 private def interpretModuleAccess (fn : Symbol )(implicit env : Env ): Object =
@@ -339,7 +339,7 @@ object Splicer {
339339
340340 private def extraMsg = " . The most common reason for that is that you apply macros in the compilation run that defines them"
341341
342- private def stopIfRuntimeException [T ](thunk : => T ): T = {
342+ private def stopIfRuntimeException [T ](thunk : => T , method : Method ): T = {
343343 try thunk
344344 catch {
345345 case ex : RuntimeException =>
@@ -352,13 +352,16 @@ object Splicer {
352352 throw new StopInterpretation (sw.toString, pos)
353353 case ex : InvocationTargetException =>
354354 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)
361363 }
364+ targetException.printStackTrace(new PrintWriter (sw))
362365 sw.write(" \n " )
363366 throw new StopInterpretation (sw.toString, pos)
364367 }
0 commit comments