sealed case class Failure(msg: String, exception: Box[Throwable], chain: Box[Failure]) extends EmptyBox with Product with Serializable
A Failure is an EmptyBox with an additional failure message
explaining the reason for its being empty. It can also optionally provide an
exception and/or a chain of previous Failures that may have caused this
one.
- Alphabetic
- By Inheritance
- Failure
- EmptyBox
- Box
- Serializable
- Serializable
- Product
- Equals
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
def
$(f: (Box[Nothing]) ⇒ Unit): Box[Nothing]
Alias for
pass. -
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
===[B >: Nothing](to: B): Boolean
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 aBox, but using this is recommended because it's clearer that the behavior will be different than the usual expectation.- Definition Classes
- Box
-
def
?~(msg: ⇒ String): Failure
Transform an
Emptyto aFailurewith the specified message. -
def
?~!(msg: ⇒ String): Failure
Chain the given
msgas aFailureahead of any failures thisBoxmay represent.Chain the given
msgas aFailureahead of any failures thisBoxmay represent.If this is an
Empty, this method behaves like?~. If it is aFailure, however, this method returns a newFailurewith the givenmsgand with itschainset to thisFailure.As with
?~, if this is aFull, we return it unchanged.- returns
A
Failurewith the message if thisBoxis anEmptybox. Chain this box to the newFailureif this is aFailure. The unchanged box if it is aFull.
-
def
asA[B](implicit m: Manifest[B]): Box[B]
Create a
Fullbox containing the specified value if this box's value is of typeBandEmptyotherwise. -
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
- val chain: Box[Failure]
-
def
choice[B](f1: (Nothing) ⇒ Box[B])(alternative: ⇒ Box[B]): Box[B]
Equivalent to
flatMap(f1).or(alternative).Equivalent to
flatMap(f1).or(alternative).- Definition Classes
- Box
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
collect[B](pf: PartialFunction[Nothing, B]): Box[B]
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
-
final
def
collectFirst[B](pf: PartialFunction[Nothing, B]): Box[B]
An alias for
collect.An alias for
collect.Although this function is different for true collections, because
Boxis really a collection of 1, the two functions are identical.- Definition Classes
- Box
-
def
compoundFailMsg(msg: ⇒ String): Box[Nothing]
Alias for
?~!.Alias for
?~!.- Definition Classes
- Box
-
def
dmap[B](dflt: ⇒ B)(f: (Nothing) ⇒ B): B
Equivalent to
map(f).openOr(dflt).Equivalent to
map(f).openOr(dflt).- Definition Classes
- Box
-
def
elements: Iterator[Nothing]
Returns an
Iteratorover the value contained in thisBox, if any. -
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(other: Any): Boolean
For
FullandEmpty, this has the expected behavior.For
FullandEmpty, 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
Boxinstead 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")
- val exception: Box[Throwable]
-
def
exceptionChain: List[Throwable]
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 thisFailure'sexception. Then, if thisFailurehas achain, walks down it and concatenates theirexceptionChainto the end of this one's.- returns
A single list of
Throwables from the most direct cause to the least direct cause of thisFailure.
-
def
exists(func: (Nothing) ⇒ Boolean): Boolean
If this
Boxcontains a value and it satisfies the specifiedfunc, returntrue.If this
Boxcontains a value and it satisfies the specifiedfunc, returntrue. Otherwise, returnfalse.- returns
trueif this Box does contain a value and it satisfies the predicate.
- Definition Classes
- Box
-
def
failMsg(msg: ⇒ String): Box[Nothing]
Alias for
?~. -
def
failureChain: List[Failure]
Flatten the
Failurechain to a List where this Failure is at the head. -
def
filter(p: (Nothing) ⇒ Boolean): Box[Nothing]
If this
Boxcontains a value and it satisfies the specifiedpredicate, return theBoxunchanged. -
def
filterMsg(msg: String)(p: (Nothing) ⇒ Boolean): Box[Nothing]
If this
Boxcontains a value and it satisfies the specifiedpredicate, return theBoxunchanged.If this
Boxcontains a value and it satisfies the specifiedpredicate, return theBoxunchanged. Otherwise, return aFailurewith the givenmsg.- returns
A
Failurewith the message if the box is empty or the predicate is not satisfied by the value contained in this Box.
-
def
filterNot(f: (Nothing) ⇒ Boolean): Box[Nothing]
If this
Boxcontains a value and it does not satisfy the specifiedf, return theBoxunchanged.If this
Boxcontains a value and it does not satisfy the specifiedf, return theBoxunchanged. Otherwise, return anEmpty.- Definition Classes
- Box
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
flatMap[B](f: (A) ⇒ Box[B]): Box[B]
Apply a function returning a
Boxto the value contained in thisBoxif it exists and return the resultingBox. -
def
flatten[B](implicit ev: <:<[Nothing, Box[B]]): Box[B]
- Definition Classes
- Box
-
def
flip[B](flipFn: (EmptyBox) ⇒ B): Box[B]
Returns a
Fullbox containing the results of applyingflipFnto this box if it is aFailure,ParamFailureorEmpty.Returns a
Fullbox containing the results of applyingflipFnto this box if it is aFailure,ParamFailureorEmpty. ReturnsEmptyif this box isFull. In other words, it "flips" the full/empty status of this Box.- Definition Classes
- Box
-
def
forall(func: (Nothing) ⇒ Boolean): Boolean
If this
Boxcontains a value and it does not satisfy the specifiedfunc, returnfalse.If this
Boxcontains a value and it does not satisfy the specifiedfunc, returnfalse. Otherwise, returntrue.- returns
true If the
Boxis empty, or if its value satisfies the predicate.
- Definition Classes
- Box
-
def
foreach[U](f: (Nothing) ⇒ U): Unit
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
Boxis empty.- Definition Classes
- Box
-
def
fullXform[T](v: T)(f: (T) ⇒ (Nothing) ⇒ T): T
If the
BoxisFull, apply the transform functionfon the valuev; otherwise, just return the value untransformed.If the
BoxisFull, apply the transform functionfon the valuev; otherwise, just return the value untransformed.The transform function is expected to be a function that will take the value
vand produce a function from the value in the box to a new value of the same type asv.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
BoxisFull, the value once transformed by the function returned byf. Otherwise, the initial valuev.
- Definition Classes
- Box
-
final
def
get: DoNotCallThisMethod
Exists to avoid the implicit conversion from
BoxtoOption.Exists to avoid the implicit conversion from
BoxtoOption. Opening aBoxunsafely should be done usingopenOrThrowException.This method always throws an exception.
- Definition Classes
- Box
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
isA[B](cls: Class[B]): Box[B]
If this box is
Fulland contains an object of typeB, returns aFullof typeBox[B].If this box is
Fulland contains an object of typeB, returns aFullof typeBox[B]. Otherwise, returnsEmpty.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)
-
def
isDefined: Boolean
Returns true if the box contains a value.
Returns true if the box contains a value.
- Definition Classes
- Box
-
def
isEmpty: Boolean
Returns
trueif thisBoxcontains no value (i.e., it isEmptyorFailureorParamFailure). -
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
iterator: Iterator[Nothing]
Returns an
Iteratorover the value contained in thisBox, if any. -
def
javaIterator[B >: Nothing]: Iterator[B]
Get a
java.util.Iteratorfrom the Box.Get a
java.util.Iteratorfrom the Box.- Definition Classes
- Box
-
def
map[B](f: (A) ⇒ B): Box[B]
Apply a function to the value contained in this
Boxif it exists and return aFullcontaining the result. -
def
messageChain: String
Reduce this
Failure's message and the messages of all chained failures a to a singleString.Reduce this
Failure's message and the messages of all chained failures a to a singleString. The resulting string links each step in the failure chain with <-, and thisFailure'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.
- val msg: String
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
openOr[B](default: ⇒ B): B
Return the value contained in this
Boxif it is full; otherwise return the specified default. -
def
openOrThrowException(justification: ⇒ String): Nothing
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
Boxif it isFull.
-
def
or[B](alternative: ⇒ Box[B]): Box[B]
Return this Box if
Full, or the specified alternative if it is empty. -
def
pass(f: (Box[Nothing]) ⇒ Unit): Box[Nothing]
Perform a side effect by passing this
Boxto the specified function and return thisBoxunmodified.Perform a side effect by passing this
Boxto the specified function and return thisBoxunmodified. Similar toforeach, except thatforeachreturnsUnit, while this method allows chained use of theBox.- returns
This box.
- Definition Classes
- Box
-
def
rootExceptionCause: Box[Throwable]
Gets the deepest exception cause, if any, which is ostensibly the root cause of this
Failure. -
def
run[T](in: ⇒ T)(f: (T, Nothing) ⇒ T): T
This method calls the specified function with the specified
invalue and the value contained in thisBox.This method calls the specified function with the specified
invalue and the value contained in thisBox. If this box is empty, returns theinvalue directly.- returns
The result of the function or the
invalue.
- Definition Classes
- Box
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toLeft[B](right: ⇒ B): Either[Nothing, B]
An
Eitherthat is aRightwith the given argumentrightif this is empty, or aLeftwith the boxed value if this isFull. -
def
toList: List[Nothing]
Returns a
Listof one element if this is Full, or an empty list if empty. -
def
toOption: Option[Nothing]
Returns the contents of this box wrapped in
Someif this isFull, orNoneif this is empty (meaning anEmpty,Failureor ParamFailure).Returns the contents of this box wrapped in
Someif this isFull, orNoneif this is empty (meaning anEmpty,Failureor ParamFailure).- Definition Classes
- Box
-
def
toRight[B](left: ⇒ B): Either[B, Nothing]
An
Eitherthat is aLeftwith the given argumentleftif this is empty, or aRightwith the boxed value if this isFull. -
def
transform[B >: Nothing](transformFn: PartialFunction[Box[Nothing], Box[B]]): Box[B]
Transforms this box using the
transformFn.Transforms this box using the
transformFn. IftransformFnis defined for this box, returns the result of applyingtransformFnto it. Otherwise, returns this box unchanged.If you want to change the content of a
Fullbox, usingmaporcollectmight be better suited to that purpose. If you want to convert anEmpty,Failureor aParamFailureinto aFullbox, you should useflip.- Definition Classes
- Box
// Returns Full("alternative") because the partial function covers the case. Full("error") transform { case Full("error") => Full("alternative") } // Returns Full(1), this Full box unchanged, because the partial function doesn't cover the case. Full(1) transform { case Full(2) => Failure("error") } // Returns this Failure("another-error") unchanged because the partial function doesn't cover the case. Failure("another-error") transform { case Failure("error", Empty, Empty) => Full("alternative") } // Returns Full("alternative") for an Empty box since `partialFn` is defined for Empty Empty transform { case Empty => Full("alternative") } // Returns Empty because the partial function is not defined for Empty Empty transform { case Failure("error", Empty, Empty) => Full("alternative") }
Example: -
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
withFilter(p: (Nothing) ⇒ Boolean): WithFilter
Makes
Boxplay better with Scalaforcomprehensions.Makes
Boxplay better with Scalaforcomprehensions.- Definition Classes
- Box
-
def
~>[T](errorCode: ⇒ T): ParamFailure[T]
Transform an
EmptyorFailureto aParamFailurewith the specified type-safe parameter.Transform an
EmptyorFailureto aParamFailurewith the specified type-safe parameter.- errorCode
A value indicating the error.
- returns
A
ParamFailurewith the specified value, unless this is already aParamFailureor aFull. If this is aFailure, theParamFailurewill preserve the message of theFailure.