trait FailureID extends AnyRef
THERE'S NOTHING WRONG WITH FAILURE!
There, now that that got your attention, let me elaborate on the intention of these types.
Basically, they are a semantically richer way of expressing common failures when developing backend-servers.
Furthermore, these exceptions being part of the
of the application
—by reading this file— you have not gauged their full potentiality, yet.
The intention is to give richer interpretations to these "common failures"
in other core
modules than could be done to the likes
of Throwable.busymachines-commons
The reason why there is a trait FailureMessage, and some types that extend Exception is that the potentiality of these types can be achieved either through a monad stack approach to building applications, or to a more vanilla scala approach, respectively.
There is a hierarchy of FailureMessage representing one single failure, in richer details.
FailureMessages represents a container of multiple FailureMessages. The intended use of the FailureMessages.id is to signal the general "context" within which the specific FailureMessages.messages where gathered. While each specific FailureMessage contains information about what went wrong.
There are the following semantically meaningful exceptions (with their plural counterparts elided) that you ought to be using: - NotFoundFailure - SemanticFailures.NotFound - UnauthorizedFailure - SemanticFailures.Unauthorized - ForbiddenFailure - SemanticFailures.Forbidden - DeniedFailure - SemanticFailures.Denied - InvalidInputFailure - SemanticFailures.InvalidInput - ConflictFailure - SemanticFailures.Conflict
Each described in the SemanticFailures docs.
These definitions are also quite flexible enough to allow multiple styles of active development:
1) The quick and dirty, "better than RuntimeException" style. Basically, you just wind up using the default constructors on the companion object, or the companion object itself
//I know I am in the middle of my domain problem, and I know that here //I can fail because "I did not find something", so I just quickly use: option.getOrElse(throw NotFoundFailure) option.getOrElse(throw NotFoundFailure("this specific option, instead of generic"))
This style should be kept just that, "quick and dirty". After the first iteration of the implementation these failures should be replaced by the ones in style 2)
2) The long term style. Where you subclass NotFoundFailure into a more meaningful exception specific to your problem domain, supply some context via the parameters, and assign it an (preferably) application-wide unique FailureID.
object RevolutionaryDomainFailures { case object CannotBeDone extends FailureID { val name = "rd_001" } //... and many others } case class SolutionNotFoundFailure(problem: String) extends NotFoundFailure( "Cannot find solution to problem:" + problem ) { override def id: FailureID = RevolutionaryDomainFailures.CannotBeDone override def parameters: Parameters = Map( "problem" -> problem ) } object Main { //... solutionToPVSNP.getOrElse(throw SolutionNotFoundFailure("P vs. NP")) solutionToHaltingProblem.getOrElse(throw SolutionNotFoundFailure("Halting Problem")) //how refined you want your failures, that's up to you. }
- Annotations
- @deprecated
- Deprecated
(Since version 0.2.0-RC8) Use the types from busymachines.core
- Since
31 Jul 2017
- Alphabetic
- By Inheritance
- FailureID
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
- abstract def name: String
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
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()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
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
- @native() @throws( ... )