Skip to content

Commit

Permalink
remove throws
Browse files Browse the repository at this point in the history
  • Loading branch information
simerplaha committed Nov 11, 2021
1 parent 55f3a6c commit e8b48d3
Show file tree
Hide file tree
Showing 25 changed files with 50 additions and 62 deletions.
2 changes: 1 addition & 1 deletion actor/src/main/scala/swaydb/test/TestActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ case class TestActor[T]()(implicit override val executionContext: ExecutionConte
scheduler.future(after) {
Option(queue.poll()) match {
case Some(item) =>
throw IO.throwable(s"Has message: ${item.getClass.getSimpleName}")
throw new Exception(s"Has message: ${item.getClass.getSimpleName}")

case None =>
()
Expand Down
4 changes: 2 additions & 2 deletions cache/src/test/scala/swaydb/data/cache/LazySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,12 @@ class LazySpec extends AnyWordSpec with Matchers with MockFactory {
def doTest(isSynchronised: Boolean, stored: Boolean) = {
val lazyValue = Lazy.io[Throwable, Int](isSynchronised, stored, None)

lazyValue.getOrSet(throw IO.throwable("failed")).left.get.getMessage shouldBe "failed"
lazyValue.getOrSet(throw new Exception("failed")).left.get.getMessage shouldBe "failed"
lazyValue.isEmpty shouldBe true
lazyValue.isDefined shouldBe false
lazyValue.get() shouldBe empty

lazyValue.set(throw IO.throwable("failed")).left.get.getMessage shouldBe "failed"
lazyValue.set(throw new Exception("failed")).left.get.getMessage shouldBe "failed"
lazyValue.isEmpty shouldBe true
lazyValue.isDefined shouldBe false
lazyValue.get() shouldBe empty
Expand Down
14 changes: 7 additions & 7 deletions core/src/main/scala/swaydb/core/data/KeyValue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ private[swaydb] object Memory {

//to do - make type-safe.
override def toRangeValue(): Value.RangeValue =
throw IO.throwable("Put cannot be converted to RangeValue")
throw new Exception("Put cannot be converted to RangeValue")

override def toMemory(): Memory.Put =
this
Expand Down Expand Up @@ -1031,7 +1031,7 @@ private[core] object Persistent {
if (offset.size == 0)
Slice.Null
else if (valuesReaderOrNull == null)
throw IO.throwable("ValuesBlock is undefined.")
throw new Exception("ValuesBlock is undefined.")
else
UnblockedReader.moveTo(offset, valuesReaderOrNull)
.copy()
Expand Down Expand Up @@ -1096,7 +1096,7 @@ private[core] object Persistent {
)

override def toRangeValue(): Value.RangeValue =
throw IO.throwable("Put cannot be converted to RangeValue")
throw new Exception("Put cannot be converted to RangeValue")

override def toMemory(): Memory.Put =
Memory.Put(
Expand Down Expand Up @@ -1138,7 +1138,7 @@ private[core] object Persistent {
if (offset.size == 0)
Slice.Null
else if (valuesReaderOrNull == null)
throw IO.throwable("ValuesBlock is undefined.")
throw new Exception("ValuesBlock is undefined.")
else
UnblockedReader.moveTo(offset, valuesReaderOrNull)
.copy()
Expand Down Expand Up @@ -1296,7 +1296,7 @@ private[core] object Persistent {
Cache.noIO[ValuesBlockOffset, Slice[Byte]](synchronised = true, stored = true, initial = None) {
(offset, _) =>
if (valuesReaderOrNull == null)
throw IO.throwable("ValuesBlock is undefined.")
throw new Exception("ValuesBlock is undefined.")
else
UnblockedReader.moveTo(offset, valuesReaderOrNull)
.copy()
Expand Down Expand Up @@ -1387,7 +1387,7 @@ private[core] object Persistent {
Cache.noIO[ValuesBlockOffset, Slice[Value.Apply]](synchronised = true, stored = true, initial = None) {
(offset, _) =>
if (valuesReaderOrNull == null) {
throw IO.throwable("ValuesBlock is undefined.")
throw new Exception("ValuesBlock is undefined.")
} else {
val bytes =
UnblockedReader.moveTo(offset, valuesReaderOrNull)
Expand Down Expand Up @@ -1522,7 +1522,7 @@ private[core] object Persistent {
Cache.noIO[ValuesBlockOffset, (Value.FromValueOption, Value.RangeValue)](synchronised = true, stored = true, initial = None) {
(offset, _) =>
if (valuesReaderOrNull == null) {
throw IO.throwable("ValuesBlock is undefined.")
throw new Exception("ValuesBlock is undefined.")
} else {
val bytes =
UnblockedReader.moveTo(offset, valuesReaderOrNull)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/swaydb/core/level/zero/LevelZero.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ private[swaydb] case class LevelZero(path: Path,
nextLevel.appendixPath

case None =>
throw IO.throwable("LevelZero does not have appendix.")
throw new Exception("LevelZero does not have appendix.")
}

override def rootPath: Path =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private[core] class PersistentCounterLog(val mod: Long,
if (!map.writeNoSync(LogEntry.Put(CounterLog.defaultKey, Slice.writeLong[Byte](count + mod)))) {
val message = s"Failed to write counter entry: $count"
logger.error(message)
throw IO.throwable(message) //:O see note above
throw new Exception(message) //:O see note above
}

count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private[core] object ValueSerializer {
applies
}
else
throw IO.throwable(s"Invalid id:$id")
throw new Exception(s"Invalid id:$id")
}
}
}
Expand Down Expand Up @@ -271,7 +271,7 @@ private[core] object ValueSerializer {
override def read(reader: ReaderBase[Byte]): (Slice[Byte], Slice[Byte]) = {
val bytes = SeqOfBytesSerializer.read(reader)
if (bytes.size != 2)
throw IO.throwable(TupleOfBytesSerializer.getClass.getSimpleName + s".read did not return a tuple. Size = ${bytes.size}")
throw new Exception(TupleOfBytesSerializer.getClass.getSimpleName + s".read did not return a tuple. Size = ${bytes.size}")
else
(bytes.head, bytes.last)
}
Expand Down Expand Up @@ -340,7 +340,7 @@ private[core] object ValueSerializer {
override def read(reader: ReaderBase[Byte]): mutable.Map[Int, Iterable[(Slice[Byte], Slice[Byte])]] = {
val format = reader.get()
if (format != formatId)
throw IO.throwable(s"Invalid formatID: $format")
throw new Exception(s"Invalid formatID: $format")
else
reader.foldLeft(mutable.Map.empty[Int, Iterable[(Slice[Byte], Slice[Byte])]]) {
case (map, reader) =>
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/swaydb/core/segment/Segment.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private[core] case object Segment extends LazyLogging {
fileSweeper: FileSweeper,
idGenerator: IDGenerator): Slice[MemorySegment] =
if (stats.isEmpty) {
throw IO.throwable("Empty key-values submitted to memory Segment.")
throw new Exception("Empty key-values submitted to memory Segment.")
} else {
val segments = ListBuffer.empty[MemorySegment]

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/swaydb/core/segment/block/Block.scala
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private[core] object Block extends LazyLogging {
)
)
else
throw IO.throwable(s"Decompressed bytes size (${decompressedBytes.size}) != decompressedLength (${compressionInfo.decompressedLength}).")
throw new Exception(s"Decompressed bytes size (${decompressedBytes.size}) != decompressedLength (${compressionInfo.decompressedLength}).")

case None =>
//no compression just skip the header bytes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package swaydb.core.segment.block.binarysearch

import swaydb.IO
import swaydb.core.data.{Persistent, PersistentOption}
import swaydb.core.segment.block._
import swaydb.core.segment.block.reader.UnblockedReader
Expand Down Expand Up @@ -98,7 +97,7 @@ private[core] case object BinarySearchIndexBlock {
state.header = compressionResult.headerBytes

// if (state.bytes.currentWritePosition > state.headerSize)
// throw IO.throwable(s"Calculated header size was incorrect. Expected: ${state.headerSize}. Used: ${state.bytes.currentWritePosition - 1}")
// throw new Exception(s"Calculated header size was incorrect. Expected: ${state.headerSize}. Used: ${state.bytes.currentWritePosition - 1}")
Some(state)
}
else
Expand All @@ -124,7 +123,7 @@ private[core] case object BinarySearchIndexBlock {

def read(header: BlockHeader[BinarySearchIndexBlockOffset]): BinarySearchIndexBlock = {
val formatId = header.headerReader.get()
val format: BinarySearchEntryFormat = BinarySearchEntryFormat.formats.find(_.id == formatId) getOrElse IO.throws(s"Invalid binary search formatId: $formatId")
val format: BinarySearchEntryFormat = BinarySearchEntryFormat.formats.find(_.id == formatId) getOrElse (throw new Exception(s"Invalid binary search formatId: $formatId"))
val valuesCount = header.headerReader.readUnsignedInt()
val bytesPerValue = header.headerReader.readInt()
val isFullIndex = header.headerReader.readBoolean()
Expand Down Expand Up @@ -221,7 +220,7 @@ private[core] case object BinarySearchIndexBlock {
binarySearchIndex: UnblockedReader[BinarySearchIndexBlockOffset, BinarySearchIndexBlock],
sortedIndex: UnblockedReader[SortedIndexBlockOffset, SortedIndexBlock],
valuesOrNull: UnblockedReader[ValuesBlockOffset, ValuesBlock])(implicit order: KeyOrder[Persistent.Partial],
keyOrder: KeyOrder[Slice[Byte]]): Persistent.PartialOption = {
keyOrder: KeyOrder[Slice[Byte]]): Persistent.PartialOption = {
val isFullIndex = binarySearchIndex == null || binarySearchIndex.block.isFullIndex
val valuesCount = if (binarySearchIndex == null) keyValuesCount else binarySearchIndex.block.valuesCount
val bytesPerValue = if (binarySearchIndex == null) sortedIndex.block.segmentMaxIndexEntrySize else binarySearchIndex.block.bytesPerValue
Expand Down Expand Up @@ -293,7 +292,7 @@ private[core] case object BinarySearchIndexBlock {
binarySearchIndex: UnblockedReader[BinarySearchIndexBlockOffset, BinarySearchIndexBlock],
sortedIndex: UnblockedReader[SortedIndexBlockOffset, SortedIndexBlock],
valuesOrNull: UnblockedReader[ValuesBlockOffset, ValuesBlock])(implicit keyOrder: KeyOrder[Slice[Byte]],
partialOrder: KeyOrder[Persistent.Partial]): BinarySearchLowerResult.Some = {
partialOrder: KeyOrder[Persistent.Partial]): BinarySearchLowerResult.Some = {

val isFullIndex = binarySearchIndex == null || binarySearchIndex.block.isFullIndex
val valuesCount = if (binarySearchIndex == null) keyValuesCount else binarySearchIndex.block.valuesCount
Expand Down Expand Up @@ -422,7 +421,7 @@ private[core] case object BinarySearchIndexBlock {
binarySearchIndexReaderOrNull: UnblockedReader[BinarySearchIndexBlockOffset, BinarySearchIndexBlock],
sortedIndexReader: UnblockedReader[SortedIndexBlockOffset, SortedIndexBlock],
valuesReaderOrNull: UnblockedReader[ValuesBlockOffset, ValuesBlock])(implicit ordering: KeyOrder[Slice[Byte]],
partialKeyOrder: KeyOrder[Persistent.Partial]): Persistent.PartialOption =
partialKeyOrder: KeyOrder[Persistent.Partial]): Persistent.PartialOption =
if (sortedIndexReader.block.isBinarySearchable) {
// binarySeeks += 1
binarySearchMatchOrLower(
Expand Down Expand Up @@ -495,7 +494,7 @@ private[core] case object BinarySearchIndexBlock {
binarySearchIndexReaderOrNull: UnblockedReader[BinarySearchIndexBlockOffset, BinarySearchIndexBlock],
sortedIndexReader: UnblockedReader[SortedIndexBlockOffset, SortedIndexBlock],
valuesReaderOrNull: UnblockedReader[ValuesBlockOffset, ValuesBlock])(implicit ordering: KeyOrder[Slice[Byte]],
partialKeyOrder: KeyOrder[Persistent.Partial]): PersistentOption = {
partialKeyOrder: KeyOrder[Persistent.Partial]): PersistentOption = {
val startFrom =
search( //A check to see if key equiv start.key to perform a simple forward seek without matching is done in SegmentSearcher
key = key,
Expand Down Expand Up @@ -545,7 +544,7 @@ private[core] case object BinarySearchIndexBlock {
binarySearchIndexReaderOrNull: UnblockedReader[BinarySearchIndexBlockOffset, BinarySearchIndexBlock],
sortedIndexReader: UnblockedReader[SortedIndexBlockOffset, SortedIndexBlock],
valuesReaderOrNull: UnblockedReader[ValuesBlockOffset, ValuesBlock])(implicit ordering: KeyOrder[Slice[Byte]],
partialOrdering: KeyOrder[Persistent.Partial]): PersistentOption =
partialOrdering: KeyOrder[Persistent.Partial]): PersistentOption =
if (sortedIndexReader.block.isBinarySearchable) {
val result =
binarySearchLower(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private[core] case object BloomFilterBlock extends LazyLogging {

state.header = compressionResult.headerBytes
// if (state.bytes.currentWritePosition > state.headerSize) {
// throw IO.throwable(s"Calculated header size was incorrect. Expected: ${state.headerSize}. Used: ${state.bytes.currentWritePosition - 1}")
// throw new Exception(s"Calculated header size was incorrect. Expected: ${state.headerSize}. Used: ${state.bytes.currentWritePosition - 1}")
// } else {
// logger.trace(s"BloomFilter stats: allocatedSpace: ${state.numberOfBits}. actualSpace: ${state.bytes.size}. maxProbe: ${state.maxProbe}")
// Some(state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package swaydb.core.segment.block.hashindex

import com.typesafe.scalalogging.LazyLogging
import swaydb.IO
import swaydb.core.data.Persistent
import swaydb.core.segment.block._
import swaydb.core.segment.block.reader.UnblockedReader
Expand Down Expand Up @@ -173,7 +172,7 @@ private[core] case object HashIndexBlock extends LazyLogging {

def read(header: BlockHeader[HashIndexBlockOffset]): HashIndexBlock = {
val formatId = header.headerReader.get()
val format = HashIndexEntryFormat.formats.find(_.id == formatId) getOrElse IO.throws(s"Invalid HashIndex formatId: $formatId")
val format = HashIndexEntryFormat.formats.find(_.id == formatId) getOrElse (throw new Exception(s"Invalid HashIndex formatId: $formatId"))
val allocatedBytes = header.headerReader.readInt()
val maxProbe = header.headerReader.readUnsignedInt()
val hit = header.headerReader.readUnsignedInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private[block] trait BlockReaderBase extends ReaderBase[Byte] with BlockCacheSou
position += 1
byte
} else {
throw IO.throwable(s"Has no more bytes. Position: $position")
throw new Exception(s"Has no more bytes. Position: $position")
}

override def read(size: Int): Slice[Byte] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private[core] case object SegmentFooterBlock {
val footerBytes = fullFooterBytes.moveTo(fullFooterBytes.size - footerSize).readRemaining()
val actualCRC = CRC32.forBytes(footerBytes dropRight ByteSizeOf.long) //drop crc bytes.
if (expectedCRC != actualCRC)
throw IO.throwable(s"Corrupted Segment: CRC Check failed. $expectedCRC != $actualCRC")
throw new Exception(s"Corrupted Segment: CRC Check failed. $expectedCRC != $actualCRC")
else
readCRCPassed(
footerStartOffset = footerStartOffset,
Expand All @@ -190,7 +190,7 @@ private[core] case object SegmentFooterBlock {
val footerReader = Reader(footerBytes)
val formatId = footerReader.readUnsignedInt()
if (formatId != SegmentBlock.formatId) {
throw IO.throwable(message = s"Invalid Segment formatId: $formatId. Expected: ${SegmentBlock.formatId}")
throw new Exception(s"Invalid Segment formatId: $formatId. Expected: ${SegmentBlock.formatId}")
} else {
val createdInLevel = footerReader.readUnsignedInt()
val rangeCount = footerReader.readUnsignedInt()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package swaydb.core.segment.block.segment.footer

import swaydb.IO
import swaydb.core.segment.block.{BlockHeader, BlockOffset, BlockOps}

object SegmentFooterBlockOffset {
Expand All @@ -13,7 +12,7 @@ object SegmentFooterBlockOffset {
SegmentFooterBlockOffset(start, size)

override def readBlock(header: BlockHeader[SegmentFooterBlockOffset]): SegmentFooterBlock =
throw IO.throwable("Footers do not have block header readers.")
throw new Exception("Footers do not have block header readers.")
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private[core] case object ValuesBlock {
state.header = compressionResult.headerBytes

// if (state.bytes.currentWritePosition > state.bytes.fromOffset + headerSize)
// throw IO.throwable(s"Calculated header size was incorrect. Expected: $headerSize. Used: ${state.bytes.currentWritePosition - 1}")
// throw new Exception(s"Calculated header size was incorrect. Expected: $headerSize. Used: ${state.bytes.currentWritePosition - 1}")

state
}
Expand Down Expand Up @@ -127,15 +127,15 @@ private[core] case object ValuesBlock {
if (length == 0)
None
else if (fromOffset < 0) {
throw IO.throwable(s"Cannot read from negative offset '$fromOffset'.")
throw new Exception(s"Cannot read from negative offset '$fromOffset'.")
} else {
val slice =
reader
.moveTo(fromOffset)
.read(length)

if (slice.size != length)
throw IO.throwable(s"Read value bytes != expected. ${slice.size} != $length.")
throw new Exception(s"Read value bytes != expected. ${slice.size} != $length.")
else
Some(slice)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ sealed trait KeyValueId {
else if (isKeyValueId_UncompressedKey(keyValueId))
keyValueId - minKey_Uncompressed_KeyValueId
else
throw IO.throwable(s"Int id: $keyValueId does not belong to ${this.getClass.getSimpleName}")
throw new Exception(s"Int id: $keyValueId does not belong to ${this.getClass.getSimpleName}")

//Note: this exceptions above and below is not expected to occur. This may only occur due to file corruption.
//instead of wrapping in IO for performance throw exception as this is not expected to occur.
Expand All @@ -67,18 +67,18 @@ sealed trait KeyValueId {
if (isKeyValueId_CompressedKey(baseId))
baseId
else
throw IO.throwable(s"Int id: $baseId does not belong to ${this.getClass.getSimpleName} ")
throw new Exception(s"Int id: $baseId does not belong to ${this.getClass.getSimpleName} ")
else if (isKeyValueId_CompressedKey(baseId + minKey_Compressed_KeyValueId))
baseId + minKey_Compressed_KeyValueId
else
throw IO.throwable(s"Int id: $baseId does not belong to ${this.getClass.getSimpleName}. Adjusted id was :${baseId + minKey_Compressed_KeyValueId}")
throw new Exception(s"Int id: $baseId does not belong to ${this.getClass.getSimpleName}. Adjusted id was :${baseId + minKey_Compressed_KeyValueId}")

//the _ is to highlight that this will return an uncompressed id. There used to be a type-safe way to handle this!
def adjustBaseIdToKeyValueIdKey_UnCompressed(baseId: Int): Int =
if (isKeyValueId_UncompressedKey(baseId + minKey_Uncompressed_KeyValueId))
baseId + minKey_Uncompressed_KeyValueId
else
throw IO.throwable(s"Int id: $baseId does not belong to ${this.getClass.getSimpleName}. Adjusted id was :${baseId + minKey_Uncompressed_KeyValueId}")
throw new Exception(s"Int id: $baseId does not belong to ${this.getClass.getSimpleName}. Adjusted id was :${baseId + minKey_Uncompressed_KeyValueId}")
}

object KeyValueId {
Expand Down
Loading

0 comments on commit e8b48d3

Please sign in to comment.