Class/Object

net.liftweb.common

ParamFailure

Related Docs: object ParamFailure | package common

Permalink

final class ParamFailure[T] extends Failure with Serializable

A ParamFailure is a Failure with an additional type-safe parameter that can allow an application to store other information related to the failure.

For example:

val loggedInUser =
  for {
    username ?~ "Missing username" ~> "error.missingUser"
    password ?~! "Missing password" ~> "error.missingPassword"
    user <- User.find("username" -> username)
    if User.checkPassword(password, user.password)
  } yield {
    user
  }

loggedInUser match {
  case ParamFailure(message, _, _, i18nKey: String) =>
    tellUser(i18n(i18nKey))
  case Failure(message, _, _) =>
    tellUser(failureMessage)
  case Empty =>
    tellUser("Unknown login failure.")
  case _ =>
    tellUser("You're in!")
}
Linear Supertypes
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. ParamFailure
  2. Failure
  3. EmptyBox
  4. Box
  5. Serializable
  6. Serializable
  7. Product
  8. Equals
  9. AnyRef
  10. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Instance Constructors

  1. new ParamFailure(msg: String, exception: Box[Throwable], chain: Box[Failure], param: T)

    Permalink

Type Members

  1. type A = Nothing

    Permalink
    Definition Classes
    Failure
  2. class WithFilter extends AnyRef

    Permalink

    Makes Box play better with Scala for comprehensions.

    Makes Box play better with Scala for comprehensions.

    Definition Classes
    Box

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. def $(f: (Box[Nothing]) ⇒ Unit): Box[Nothing]

    Permalink

    Alias for pass.

    Alias for pass.

    Definition Classes
    Box
  4. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  5. def ===[B >: Nothing](to: B): Boolean

    Permalink

    Returns true if the value contained in this box is equal to the specified value.

    Returns true if the value contained in this box is equal to the specified value. This is the same thing that == does when it's handed a value that isn't a Box, but using this is recommended because it's clearer that the behavior will be different than the usual expectation.

    Definition Classes
    Box
  6. def ?~(msg: ⇒ String): Failure

    Permalink

    Transform an Empty to a Failure with the specified message.

    Transform an Empty to a Failure with the specified message. Otherwise returns the same box.

    returns

    A Failure with the message if this Box is Empty, this box otherwise.

    Definition Classes
    FailureEmptyBoxBox
    Note

    This means a Failure will also remain unchanged; see ?~! to change these.

  7. def ?~!(msg: ⇒ String): Failure

    Permalink

    Chain the given msg as a Failure ahead of any failures this Box may represent.

    Chain the given msg as a Failure ahead of any failures this Box may represent.

    If this is an Empty, this method behaves like ?~. If it is a Failure, however, this method returns a new Failure with the given msg and with its chain set to this Failure.

    As with ?~, if this is a Full, we return it unchanged.

    returns

    A Failure with the message if this Box is an Empty box. Chain this box to the new Failure if this is a Failure. The unchanged box if it is a Full.

    Definition Classes
    FailureEmptyBoxBox
  8. def asA[B](implicit m: Manifest[B]): Box[B]

    Permalink

    Create a Full box containing the specified value if this box's value is of type B and Empty otherwise.

    Create a Full box containing the specified value if this box's value is of type B and Empty otherwise.

    For example:

    scala> Full("boom").asA[Int]
    res0: net.liftweb.common.Box[Int] = Empty
    
    scala> Full(5).asA[Int]
    res1: net.liftweb.common.Box[Int] = Full(5)
    Definition Classes
    FailureBox
  9. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  10. val chain: Box[Failure]

    Permalink
    Definition Classes
    ParamFailureFailure
  11. def choice[B](f1: (Nothing) ⇒ Box[B])(alternative: ⇒ Box[B]): Box[B]

    Permalink

    Equivalent to flatMap(f1).or(alternative).

    Equivalent to flatMap(f1).or(alternative).

    Definition Classes
    Box
  12. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  13. final def collect[B](pf: PartialFunction[Nothing, B]): Box[B]

    Permalink

    If the partial function is defined at the current Box's value, apply the partial function.

    If the partial function is defined at the current Box's value, apply the partial function.

    Definition Classes
    Box
  14. final def collectFirst[B](pf: PartialFunction[Nothing, B]): Box[B]

    Permalink

    An alias for collect.

    An alias for collect.

    Although this function is different for true collections, because Box is really a collection of 1, the two functions are identical.

    Definition Classes
    Box
  15. def compoundFailMsg(msg: ⇒ String): Box[Nothing]

    Permalink

    Alias for ?~!.

    Alias for ?~!.

    Definition Classes
    Box
  16. def dmap[B](dflt: ⇒ B)(f: (Nothing) ⇒ B): B

    Permalink

    Equivalent to map(f).openOr(dflt).

    Equivalent to map(f).openOr(dflt).

    Definition Classes
    Box
  17. def elements: Iterator[Nothing]

    Permalink

    Returns an Iterator over the value contained in this Box, if any.

    Returns an Iterator over the value contained in this Box, if any.

    Definition Classes
    Box
  18. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  19. def equals(that: Any): Boolean

    Permalink

    For Full and Empty, this has the expected behavior.

    For Full and Empty, this has the expected behavior. Equality in terms of Failure checks for equivalence of failure causes:

    Failure("boom") == Failure("boom")
    Failure("bam") != Failure("boom")
    Failure("boom", Full(someException), Empty) != Failure("boom")

    For other values, determines equality based upon the contents of this Box instead of the box itself. As a result, it is not symmetric. As an example:

    val foo = "foo"
    val boxedFoo = Full(foo)
    foo == boxedFoo //is false
    boxedFoo == foo //is true

    It is safest to use === explicitly when you're looking for this behavior, and use == only for box-to-box comparisons:

    Full("magic") == Full("magic")
    Full("magic") != Full("another")
    Full("magic") != Empty
    Full("magic") != Failure("something's gone wrong")
    Definition Classes
    ParamFailureFailureBox → Equals → AnyRef → Any
  20. val exception: Box[Throwable]

    Permalink
    Definition Classes
    ParamFailureFailure
  21. def exceptionChain: List[Throwable]

    Permalink

    Return a list of the exceptions that led to this Failure.

    Return a list of the exceptions that led to this Failure. First, unflattens the list of causes of this Failure's exception. Then, if this Failure has a chain, walks down it and concatenates their exceptionChain to the end of this one's.

    returns

    A single list of Throwables from the most direct cause to the least direct cause of this Failure.

    Definition Classes
    Failure
  22. def exists(func: (Nothing) ⇒ Boolean): Boolean

    Permalink

    If this Box contains a value and it satisfies the specified func, return true.

    If this Box contains a value and it satisfies the specified func, return true. Otherwise, return false.

    returns

    true if this Box does contain a value and it satisfies the predicate.

    Definition Classes
    Box
  23. def failMsg(msg: ⇒ String): Box[Nothing]

    Permalink

    Alias for ?~.

    Alias for ?~.

    Definition Classes
    Box
  24. def failureChain: List[Failure]

    Permalink

    Flatten the Failure chain to a List where this Failure is at the head.

    Flatten the Failure chain to a List where this Failure is at the head.

    Definition Classes
    Failure
  25. def filter(p: (Nothing) ⇒ Boolean): Box[Nothing]

    Permalink

    If this Box contains a value and it satisfies the specified predicate, return the Box unchanged.

    If this Box contains a value and it satisfies the specified predicate, return the Box unchanged. Otherwise, return an Empty.

    Definition Classes
    EmptyBoxBox
  26. def filterMsg(msg: String)(p: (Nothing) ⇒ Boolean): Box[Nothing]

    Permalink

    If this Box contains a value and it satisfies the specified predicate, return the Box unchanged.

    If this Box contains a value and it satisfies the specified predicate, return the Box unchanged. Otherwise, return a Failure with the given msg.

    returns

    A Failure with the message if the box is empty or the predicate is not satisfied by the value contained in this Box.

    Definition Classes
    Box
    See also

    filter

  27. def filterNot(f: (Nothing) ⇒ Boolean): Box[Nothing]

    Permalink

    If this Box contains a value and it does not satisfy the specified f, return the Box unchanged.

    If this Box contains a value and it does not satisfy the specified f, return the Box unchanged. Otherwise, return an Empty.

    Definition Classes
    Box
  28. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  29. def flatMap[B](f: (A) ⇒ Box[B]): Box[B]

    Permalink

    Apply a function returning a Box to the value contained in this Box if it exists and return the resulting Box.

    Apply a function returning a Box to the value contained in this Box if it exists and return the resulting Box. If this Box is not already Full, return this box unchanged.

    Definition Classes
    FailureBox
    Note

    This means that using flatMap with a Failure will preserve the Failure.

  30. def forall(func: (Nothing) ⇒ Boolean): Boolean

    Permalink

    If this Box contains a value and it does not satisfy the specified func, return false.

    If this Box contains a value and it does not satisfy the specified func, return false. Otherwise, return true.

    returns

    true If the Box is empty, or if its value satisfies the predicate.

    Definition Classes
    Box
  31. def foreach[U](f: (Nothing) ⇒ U): Unit

    Permalink

    Perform a side effect by calling the specified function with the value contained in this box.

    Perform a side effect by calling the specified function with the value contained in this box. The function does not run if this Box is empty.

    Definition Classes
    Box
  32. def fullXform[T](v: T)(f: (T) ⇒ (Nothing) ⇒ T): T

    Permalink

    If the Box is Full, apply the transform function f on the value v; otherwise, just return the value untransformed.

    If the Box is Full, apply the transform function f on the value v; otherwise, just return the value untransformed.

    The transform function is expected to be a function that will take the value v and produce a function from the value in the box to a new value of the same type as v.

    For example:

    val myBox = Full(10)
    myBox.fullXForm("No teddy bears left.")({ message =>
      { teddyBears: Int =>
        s"$message Oh wait, there are $teddyBears left!"
      }
    })
    T

    The type of the initial value, default value, and transformed value.

    returns

    If the Box is Full, the value once transformed by the function returned by f. Otherwise, the initial value v.

    Definition Classes
    Box
  33. final def get: DoNotCallThisMethod

    Permalink

    Exists to avoid the implicit conversion from Box to Option.

    Exists to avoid the implicit conversion from Box to Option. Opening a Box unsafely should be done using openOrThrowException.

    This method always throws an exception.

    Definition Classes
    Box
  34. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  35. def hashCode(): Int

    Permalink
    Definition Classes
    ParamFailureFailure → AnyRef → Any
  36. def isA[B](cls: Class[B]): Box[B]

    Permalink

    If this box is Full and contains an object of type B, returns a Full of type Box[B].

    If this box is Full and contains an object of type B, returns a Full of type Box[B]. Otherwise, returns Empty.

    This is basically a Java-friendly version of asA, which you should prefer when using Scala.

    For example:

    scala> Full("boom").isA(classOf[Int])
    res0: net.liftweb.common.Box[Int] = Empty
    
    scala> Full(5).isA(classOf[Int])
    res1: net.liftweb.common.Box[Int] = Full(5)
    Definition Classes
    FailureBox
  37. def isDefined: Boolean

    Permalink

    Returns true if the box contains a value.

    Returns true if the box contains a value.

    Definition Classes
    Box
  38. def isEmpty: Boolean

    Permalink

    Returns true if this Box contains no value (i.e., it is Empty or Failure or ParamFailure).

    Returns true if this Box contains no value (i.e., it is Empty or Failure or ParamFailure).

    Definition Classes
    EmptyBoxBox
  39. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  40. def iterator: Iterator[Nothing]

    Permalink

    Returns an Iterator over the value contained in this Box, if any.

    Returns an Iterator over the value contained in this Box, if any.

    Synonym for elements.

    Definition Classes
    Box
  41. def javaIterator[B >: Nothing]: Iterator[B]

    Permalink

    Get a java.util.Iterator from the Box.

    Get a java.util.Iterator from the Box.

    Definition Classes
    Box
  42. def map[B](f: (A) ⇒ B): Box[B]

    Permalink

    Apply a function to the value contained in this Box if it exists and return a Full containing the result.

    Apply a function to the value contained in this Box if it exists and return a Full containing the result. If this Box is not already Full, return the unchanged box.

    Definition Classes
    FailureBox
    Note

    This means that using map with a Failure will preserve the Failure.

  43. def messageChain: String

    Permalink

    Reduce this Failure's message and the messages of all chained failures a to a single String.

    Reduce this Failure's message and the messages of all chained failures a to a single String. The resulting string links each step in the failure chain with <-, and this Failure's message is last.

    For example:

    scala> Failure("It's all gone wrong.") ?~! "Something's gone wrong." ?~! "It's all sideways"
    res0: net.liftweb.common.Failure = Failure(It's all sideways,Empty,
            Full(Failure(Something's gone wrong.,Empty,
              Full(Failure(It's all gone wrong.,Empty,Empty)))))
    scala> res0.messageChain
    res1: String = It's all sideways <- Something's gone wrong. <- It's all gone wrong.
    Definition Classes
    Failure
  44. val msg: String

    Permalink
    Definition Classes
    ParamFailureFailure
  45. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  46. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  47. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  48. def openOr[B](default: ⇒ B): B

    Permalink

    Return the value contained in this Box if it is full; otherwise return the specified default.

    Return the value contained in this Box if it is full; otherwise return the specified default. Equivalent to Option's getOrElse.

    Definition Classes
    EmptyBoxBox
  49. def openOrThrowException(justification: String): Nothing

    Permalink

    The only time when you should be using this method is if the value is guaranteed to be available based on a guard outside of the method.

    The only time when you should be using this method is if the value is guaranteed to be available based on a guard outside of the method. In these cases, please provide that information in the justification String. For example, User.currentUser.openOrThrowException("This snippet is only used on pages where the user is logged in"). For tests, use == or === instead. See the class documentation for more information.

    A valid justification for using this method should not be "I want my code to fail fast when I call it." Using exceptions in the core logic of your application should be strongly discouraged.

    justification

    Justify why calling this method is okay and why it will not result in an exception being thrown. This serves both as mandatory documentation and as a very clear indication of what unexpected thing happened in the event you were wrong about the guard.

    returns

    The contents of the Box if it is Full.

    Definition Classes
    FailureEmptyBoxBox
    Exceptions thrown

    NullPointerException If you attempt to call it on an EmptyBox, with a message that includes the provided justification.

  50. def or[B](alternative: ⇒ Box[B]): Box[B]

    Permalink

    Return this Box if Full, or the specified alternative if it is empty.

    Return this Box if Full, or the specified alternative if it is empty. Equivalent to Option's orElse.

    Definition Classes
    EmptyBoxBox
  51. val param: T

    Permalink
  52. def pass(f: (Box[Nothing]) ⇒ Unit): Box[Nothing]

    Permalink

    Perform a side effect by passing this Box to the specified function and return this Box unmodified.

    Perform a side effect by passing this Box to the specified function and return this Box unmodified. Similar to foreach, except that foreach returns Unit, while this method allows chained use of the Box.

    returns

    This box.

    Definition Classes
    Box
  53. def rootExceptionCause: Box[Throwable]

    Permalink

    Gets the deepest exception cause, if any, which is ostensibly the root cause of this Failure.

    Gets the deepest exception cause, if any, which is ostensibly the root cause of this Failure.

    Definition Classes
    Failure
  54. def run[T](in: ⇒ T)(f: (T, Nothing) ⇒ T): T

    Permalink

    This method calls the specified function with the specified in value and the value contained in this Box.

    This method calls the specified function with the specified in value and the value contained in this Box. If this box is empty, returns the in value directly.

    returns

    The result of the function or the in value.

    Definition Classes
    Box
  55. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  56. def toLeft[B](right: ⇒ B): Either[Nothing, B]

    Permalink

    An Either that is a Right with the given argument right if this is empty, or a Left with the boxed value if this is Full.

    An Either that is a Right with the given argument right if this is empty, or a Left with the boxed value if this is Full.

    Definition Classes
    Box
  57. def toList: List[Nothing]

    Permalink

    Returns a List of one element if this is Full, or an empty list if empty.

    Returns a List of one element if this is Full, or an empty list if empty.

    Definition Classes
    Box
  58. def toOption: Option[Nothing]

    Permalink

    Returns the contents of this box wrapped in Some if this is Full, or None if this is empty (meaning an Empty, Failure or ParamFailure).

    Returns the contents of this box wrapped in Some if this is Full, or None if this is empty (meaning an Empty, Failure or ParamFailure).

    Definition Classes
    Box
  59. def toRight[B](left: ⇒ B): Either[B, Nothing]

    Permalink

    An Either that is a Left with the given argument left if this is empty, or a Right with the boxed value if this is Full.

    An Either that is a Left with the given argument left if this is empty, or a Right with the boxed value if this is Full.

    Definition Classes
    Box
  60. def toString(): String

    Permalink
    Definition Classes
    ParamFailureFailure → AnyRef → Any
  61. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  62. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  63. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  64. def withFilter(p: (Nothing) ⇒ Boolean): WithFilter

    Permalink

    Makes Box play better with Scala for comprehensions.

    Makes Box play better with Scala for comprehensions.

    Definition Classes
    Box
  65. def ~>[T](errorCode: ⇒ T): ParamFailure[T]

    Permalink

    Transform an Empty or Failure to a ParamFailure with the specified type-safe parameter.

    Transform an Empty or Failure to a ParamFailure with the specified type-safe parameter.

    errorCode

    A value indicating the error.

    returns

    A ParamFailure with the specified value, unless this is already a ParamFailure or a Full. If this is a Failure, the ParamFailure will preserve the message of the Failure.

    Definition Classes
    ParamFailureFailureEmptyBoxBox

Inherited from Failure

Inherited from EmptyBox

Inherited from Box[Nothing]

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped