summaryrefslogtreecommitdiff
path: root/cask/src/cask/router/Result.scala
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2019-09-16 08:58:31 +0800
committerLi Haoyi <haoyi.sg@gmail.com>2019-09-16 08:58:31 +0800
commit583893aff7e39e085dbf5bec27c9b0b24e5e8d2e (patch)
treeb2cf94c9bef2824159d8c9bd4f4867163a6ef36c /cask/src/cask/router/Result.scala
parent4851f249c8124ce725576f4f87f097f16e2f3843 (diff)
downloadcask-583893aff7e39e085dbf5bec27c9b0b24e5e8d2e.tar.gz
cask-583893aff7e39e085dbf5bec27c9b0b24e5e8d2e.tar.bz2
cask-583893aff7e39e085dbf5bec27c9b0b24e5e8d2e.zip
Break up `Router.scala` into a `router/` folder with multiple files
Diffstat (limited to 'cask/src/cask/router/Result.scala')
-rw-r--r--cask/src/cask/router/Result.scala66
1 files changed, 66 insertions, 0 deletions
diff --git a/cask/src/cask/router/Result.scala b/cask/src/cask/router/Result.scala
new file mode 100644
index 0000000..52ef0f8
--- /dev/null
+++ b/cask/src/cask/router/Result.scala
@@ -0,0 +1,66 @@
+package cask.router
+
+
+
+
+/**
+ * Represents what comes out of an attempt to invoke an [[EntryPoint]].
+ * Could succeed with a value, but could fail in many different ways.
+ */
+sealed trait Result[+T]{
+ def map[V](f: T => V): Result[V]
+}
+object Result{
+
+ /**
+ * Invoking the [[EntryPoint]] was totally successful, and returned a
+ * result
+ */
+ case class Success[T](value: T) extends Result[T]{
+ def map[V](f: T => V) = Success(f(value))
+ }
+
+ /**
+ * Invoking the [[EntryPoint]] was not successful
+ */
+ sealed trait Error extends Result[Nothing]{
+ def map[V](f: Nothing => V) = this
+ }
+
+
+ object Error{
+
+
+ /**
+ * Invoking the [[EntryPoint]] failed with an exception while executing
+ * code within it.
+ */
+ case class Exception(t: Throwable) extends Error
+
+ /**
+ * Invoking the [[EntryPoint]] failed because the arguments provided
+ * did not line up with the arguments expected
+ */
+ case class MismatchedArguments(missing: Seq[ArgSig[_, _, _, _]],
+ unknown: Seq[String]) extends Error
+ /**
+ * Invoking the [[EntryPoint]] failed because there were problems
+ * deserializing/parsing individual arguments
+ */
+ case class InvalidArguments(values: Seq[ParamError]) extends Error
+ }
+
+ sealed trait ParamError
+ object ParamError{
+ /**
+ * Something went wrong trying to de-serialize the input parameter;
+ * the thrown exception is stored in [[ex]]
+ */
+ case class Invalid(arg: ArgSig[_, _, _, _], value: String, ex: Throwable) extends ParamError
+ /**
+ * Something went wrong trying to evaluate the default value
+ * for this input parameter
+ */
+ case class DefaultFailed(arg: ArgSig[_, _, _, _], ex: Throwable) extends ParamError
+ }
+} \ No newline at end of file