Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jrudolph/better-future-exceptions
A POC for better exception reporting for futures
https://github.com/jrudolph/better-future-exceptions
Last synced: 25 days ago
JSON representation
A POC for better exception reporting for futures
- Host: GitHub
- URL: https://github.com/jrudolph/better-future-exceptions
- Owner: jrudolph
- Created: 2013-07-16T10:22:32.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-08-20T14:26:34.000Z (about 10 years ago)
- Last Synced: 2023-04-11T05:18:11.219Z (over 1 year ago)
- Language: Scala
- Size: 137 KB
- Stars: 12
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Demo for better exception reporting for futures (macro-based)
When futures fail exceptions often contain too little context to determine the path of
composition leading to the error. This is a proof-of-concept how to use static source code
context info gathered through a macro (basically a simple implementation of SIP-19 with macros)
to annotate exceptions with the composition path.Example
-------```scala
import scala.concurrent.ExecutionContextobject FutureTest extends App {
import scala.concurrent.ExecutionContext.Implicits.global
//import scala.concurrent.{ Future => RichFuture }object Transformer {
def div0(f: RichFuture[Int])(implicit ctx: ExecutionContext): RichFuture[Int] =
f.flatMap { i =>
val j = i / 0
RichFuture { Thread.sleep(1000); j + 12 } }
}val f = RichFuture {
Thread.sleep(2000)
42
}val res = Transformer.div0(f)
res.onComplete {
case e => println("Finished with: "+e)
}Thread.sleep(5000)
}
```prints
```
Finished with: Failure(net.virtualvoid.futures.RichFutureException: Exception '/ by zero' in future called through this stack:
CallInfo(CallSite(net.virtualvoid.futures.FutureTest.Transformer,Some(div0),FutureTest.scala,13),flatMap)
CallInfo(CallSite(net.virtualvoid.futures.FutureTest,None,FutureTest.scala,19),RichFuture())
)
```This demo was prompted by a [thread on scala-user](https://groups.google.com/d/topic/scala-user/BjgQpWeqA0w/discussion).