mirror of https://github.com/sbt/sbt.git
Merge pull request #195 from eed3si9n/wip/cache
throw error on deserialization error
This commit is contained in:
commit
473d42ac78
|
|
@ -0,0 +1,5 @@
|
|||
package sbt
|
||||
package internal
|
||||
package util
|
||||
|
||||
class EmptyCacheError extends RuntimeException
|
||||
|
|
@ -4,6 +4,7 @@ import java.io.{ Closeable, InputStream }
|
|||
import scala.util.control.NonFatal
|
||||
import sjsonnew.{ IsoString, JsonReader, SupportConverter }
|
||||
import sbt.io.{ IO, Using }
|
||||
import sbt.internal.util.EmptyCacheError
|
||||
|
||||
trait Input extends Closeable {
|
||||
def read[T: JsonReader](): T
|
||||
|
|
@ -28,7 +29,11 @@ class PlainInput[J: IsoString](input: InputStream, converter: SupportConverter[J
|
|||
}
|
||||
}
|
||||
|
||||
def read[T: JsonReader]() = converter.fromJson(isoFormat.from(readFully())).get
|
||||
def read[T: JsonReader](): T = {
|
||||
val str = readFully()
|
||||
if (str == "") throw new EmptyCacheError()
|
||||
else converter.fromJson(isoFormat.from(str)).get
|
||||
}
|
||||
|
||||
def close() = input.close()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import scala.util.{ Failure, Try, Success }
|
|||
import java.io.File
|
||||
import sbt.io.IO
|
||||
import sbt.io.syntax._
|
||||
import sbt.internal.util.EmptyCacheError
|
||||
|
||||
import sjsonnew.JsonFormat
|
||||
import sjsonnew.support.murmurhash.Hasher
|
||||
|
|
@ -178,7 +179,9 @@ object Tracked {
|
|||
def save(store: CacheStore, value: I): Unit = {
|
||||
Hasher.hash(value) match {
|
||||
case Success(keyHash) => store.write[Long](keyHash.toLong)
|
||||
case Failure(_) => ()
|
||||
case Failure(e) =>
|
||||
if (isStrictMode) throw e
|
||||
else ()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -187,12 +190,19 @@ object Tracked {
|
|||
case Success(prev: Long) =>
|
||||
Hasher.hash(value) match {
|
||||
case Success(keyHash: Int) => keyHash.toLong != prev
|
||||
case Failure(_) => true
|
||||
case Failure(e) =>
|
||||
if (isStrictMode) throw e
|
||||
else true
|
||||
}
|
||||
case Failure(_) => true
|
||||
case Failure(_: EmptyCacheError) => true
|
||||
case Failure(e) =>
|
||||
if (isStrictMode) throw e
|
||||
else true
|
||||
}
|
||||
}
|
||||
|
||||
private[sbt] def isStrictMode: Boolean =
|
||||
java.lang.Boolean.getBoolean("sbt.strict")
|
||||
}
|
||||
|
||||
trait Tracked {
|
||||
|
|
|
|||
Loading…
Reference in New Issue