Skip to content
Browse files

change validation.fail.toOption to use a fold for compatibility with…

… scalaz7
  • Loading branch information...
1 parent 04fedf8 commit 52be281ef0c64cd72883e05def784eeab3ad0858 @stew stew committed Dec 27, 2012
View
12 commands/src/main/scala/org/scalatra/commands/CommandHandler.scala
@@ -15,15 +15,19 @@ trait CommandHandler {
val res = (allCatch withApply (serverError(cmd.getClass.getName, _))) {
handle.lift(cmd).map(_.map(_.asInstanceOf[S])) | ValidationError("Don't know how to handle: " + cmd.getClass.getName, UnknownError).failNel
}
- val ftext = "with %d failures\n%s".format(~res.fail.toOption.map(_.list.size), ~res.fail.toOption.map(_.list))
- commandLogger.debug("Command [%s] executed %s." format (cmd.getClass.getName, res.isSuccess ? "successfully." | ftext))
+
+ val resultLog = res.fold(
+ { failures => "with %d failures\n%s".format(failures.tail.size + 1, failures.list) },
+ { _ => "successfully" }
+ )
+ commandLogger.debug("Command [%s] executed %s." format (cmd.getClass.getName, resultLog))
res
} else {
val f = cmd.errors.map(_.validation) collect {
case Failure(e) e
}
commandLogger.debug("Command [%s] executed with %d failures.\n%s" format (cmd.getClass.getName, f.size, f.toList))
- nel(f.head, f.tail: _*).fail
+ NonEmptyList(f.head, f.tail: _*).fail
}
}
@@ -35,4 +39,4 @@ trait CommandHandler {
type Handler = PartialFunction[ModelCommand[_], ModelValidation[_]]
protected def handle: Handler
-}
+}
View
2 commands/src/main/scala/org/scalatra/commands/binding.scala
@@ -92,7 +92,7 @@ sealed trait Binding {
def name: String = field.name
def validation: FieldValidation[T] = field.value
def value: Option[T] = field.value.toOption
- def error: Option[ValidationError] = field.value.fail.toOption
+ def error: Option[ValidationError] = field.value.fold(_.some, _=>None)
def isValid = validation.isSuccess
def isInvalid = validation.isFailure
View
2 commands/src/main/scala/org/scalatra/commands/field.scala
@@ -416,7 +416,7 @@ class Field[A:Manifest](descr: FieldDescriptor[A], command: Command) {
def validation: FieldValidation[A] = binding.field.value.asInstanceOf[FieldValidation[A]]
def value: Option[A] = binding.field.value.toOption.asInstanceOf[Option[A]]
def defaultValue: A = descr.defaultValue
- def error: Option[ValidationError] = binding.field.value.fail.toOption
+ def error: Option[ValidationError] = binding.field.value.fold(_.some, _=>None)
def original = binding.original
def binding: Binding = command.bindings(name)

0 comments on commit 52be281

Please sign in to comment.
Something went wrong with that request. Please try again.