Or-ing two Failures should somehow combine them #1184

Open
romkal opened this Issue Jan 12, 2012 · 2 comments

4 participants

@romkal

Two failures that are or-ed should return a failure that somehow combines both causes.

Example:


$ def getFromProperties = Failure("Property not set")
$ def getFromFilesystem = Failure("File doesn't exist")
$ def getFromDb = Failure("DB not configured")
$ def getSomething : Box[Something] = getFromProperties or getFromFilesystem or getFromDb

Currently:


$ getSomething
Failure("DB not configured")

Desired behaviour:
Something that can give all 3 messages/exceptions if all of them failed because current behaviour swallows exceptions and return only the last one, that might be not the one that the user is interested in.
Or-ing Failure and Empty can return the one Failure or maybe some combined Failure that has both?
Just chaining might be not enough, because it's not clear how or() result can chain two Failures that have chains themselves. Maybe it would be useful to have MultiFailure class extending Failure just as there is ParamFailure? Or maybe Failure.chain should be List[Failure] not Box[Failure]?

@dpp dpp was assigned Mar 1, 2012
@Shadowfiend
Lift Web Framework member

👎 on this behavior. I think or has a clear behavior across Box. This sounds like a better solution would be a separate function that chains two Failures together. It could be similar to compoundFailMsg, but instead of just creating a new failure with the message chain, it would:

  • If both are Failures and only one has a chain, produce a copy of the Failure with no chain whose chain points to the one with an existing chain.
  • If one is an Empty, return the Failure.
  • If both are Failures and both have chains, maybe walk one of the chains until its end and make its chain point to the other failure?

Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment