diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-02-03 23:41:33 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-02-03 23:41:33 -0800 |
commit | 3980cdc6cde53865d77ea4961c6264c11b15a73a (patch) | |
tree | f63a31c4bd095f46e5ea0bac96617998a9d13e97 /core/src | |
parent | 7e44da8a8b97f2a2e5d2de489369d5075a6e1ea7 (diff) | |
download | mill-3980cdc6cde53865d77ea4961c6264c11b15a73a.tar.gz mill-3980cdc6cde53865d77ea4961c6264c11b15a73a.tar.bz2 mill-3980cdc6cde53865d77ea4961c6264c11b15a73a.zip |
Show a proper error message when invoking a command fails
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/mill/main/Resolve.scala | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/core/src/mill/main/Resolve.scala b/core/src/mill/main/Resolve.scala index 42b9eeb8..fa39e81c 100644 --- a/core/src/mill/main/Resolve.scala +++ b/core/src/mill/main/Resolve.scala @@ -4,6 +4,7 @@ import mill.define._ import mill.define.TaskModule import ammonite.main.Router import ammonite.main.Router.EntryPoint +import ammonite.util.Res object Resolve { def resolve[T, V](remainingSelector: List[Segment], @@ -23,16 +24,23 @@ object Resolve { .find(_.label == last) .map(Right(_)) - def invokeCommand(target: mill.Module, name: String) = { + def invokeCommand(target: mill.Module, name: String) = for{ + (cls, entryPoints) <- discover.value.filterKeys(_.isAssignableFrom(target.getClass)) + ep <- entryPoints + if ep._2.name == name + } yield ammonite.main.Scripts.runMainMethod( + target, + ep._2.asInstanceOf[EntryPoint[mill.Module]], + ammonite.main.Scripts.groupArgs(rest.toList) + ) match{ + case Res.Success(v) => Right(v) + case Res.Failure(msg) => Left(msg) + case Res.Exception(ex, msg) => + val sw = new java.io.StringWriter() + ex.printStackTrace(new java.io.PrintWriter(sw)) + val prefix = if (msg.nonEmpty) msg + "\n" else msg + Left(prefix + sw.toString) - for{ - (cls, entryPoints) <- discover.value.filterKeys(_.isAssignableFrom(target.getClass)) - ep <- entryPoints - if ep._2.name == name - } yield ep._2.asInstanceOf[EntryPoint[mill.Module]].invoke(target, ammonite.main.Scripts.groupArgs(rest.toList)) match { - case Router.Result.Success(v) => Right(v) - case _ => Left(s"Command failed $last") - } } val runDefault = for{ |