Methods to handle error box in Loggable trait
Baed on the thread here: https://groups.google.com/d/topic/liftweb/BGCoA9K0mUM/discussion
It would be nice it logging methods in trait Loggable were aware of the Failure object, as it is a common citizen in Lift based application - in my code, more than exception.
The pattern I met commonly is something looking like:
Of course, it seems that there is a lot of not generic part here (message text, logging level, etc), and so there is a lot of open question about the implementation details.
Moreover, in a lot of my use-cases, Empty is a Failure without message (and not a "no response" one), and in fact, what I am doing is more something like:
It would be nice it logging methods in trait Loggable were aware of the Failure object, as it is a common citizen in Lift based application - in my code, more than exception.
The pattern I met commonly is something looking like:
class MyClass extends Loggable {
(for { .... sequence of Box }) match {
case Empty => ...
case Full(x) => ...
case f:Failure =>
logger.error("Error when processing action. Error message: " + f.messageChain)
f.exception.foreach { e => logger.debug("Exception leading to that error", e)
}
}
Of course, it seems that there is a lot of not generic part here (message text, logging level, etc), and so there is a lot of open question about the implementation details.
Moreover, in a lot of my use-cases, Empty is a Failure without message (and not a "no response" one), and in fact, what I am doing is more something like:
class MyClass extends Loggable {
(for { .... sequence of Box }) match {
case Full(x) => ...
case e:EmptyBox => //because we don't want to be able to miss an Empty, even if each previous steps of the for loop use "?~!" - it's hard to debug otherwise
val error = (e ?~! "Error when processing action.")
logger.error( error.messageChain )
error.exception.foreach { ex => logger.debug("Exception leading to that error", ex)
}
}
Leave a comment
(In revision:18d569232ef2c75d135fd7dad73847bb842fe188) Closes #856. Makes Box a first class citizen in Loggable
Closes #861. Additional goodies for getting Exceptions from Failure
Ref #886. Makes user agent stuff more flexible
Branch: master
Closes #861. Additional goodies for getting Exceptions from Failure
Ref #886. Makes user agent stuff more flexible
Branch: master