Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading an invalid object should not throw any exceptions #69

Merged
merged 1 commit into from
Mar 9, 2015

Conversation

tindzk
Copy link
Contributor

@tindzk tindzk commented Feb 15, 2015

This currently prevents us from easily defining our own composite
readers, which is often necessary; see #31 and #68. Without the
exceptions, implicitly[Reader[_]].read calls can be chained using
orElse(), as done internally in uPickle.

sealed trait Base
case class Child1() extends Base
case class Child2() extends Base

import upickle._
implicit val BaseR: Reader[Base] = Reader[Base](
  implicitly[Reader[Child1]].read
    .orElse(implicitly[Reader[Child2]].read)
)

The exceptions are only useful for debugging purposes.

This currently prevents us from easily defining our own composite
readers, which is often necessary; see com-lihaoyi#31 and com-lihaoyi#68. Without the
exceptions, implicitly[Reader[_]].read calls can be chained using
orElse(), as done internally in uPickle.

```scala
sealed trait Base
case class Child1() extends Base
case class Child2() extends Base

import upickle._
implicit val BaseR: Reader[Base] = Reader[Base](
  implicitly[Reader[Child1]].read
    .orElse(implicitly[Reader[Child2]].read)
)
```

The exceptions are only useful for debugging purposes.
lihaoyi added a commit that referenced this pull request Mar 9, 2015
Reading an invalid object should not throw any exceptions
@lihaoyi lihaoyi merged commit e0816d7 into com-lihaoyi:master Mar 9, 2015
@lihaoyi
Copy link
Member

lihaoyi commented Mar 9, 2015

Looks reasonable. In future it may be worth converting the PartialFunction[T, R] reads into a T => Either[Error, R] so we can preserve both the rich-error-data as well as the chainability

lihaoyi pushed a commit that referenced this pull request Jan 25, 2016
…69 by introducing custom subclass of PartialFunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants