Skip to content

Commit

Permalink
Supply more information to network-related exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
NichtStudioCode committed Nov 11, 2024
1 parent 502eea5 commit f76d63b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class NetworkCluster(val uuid: UUID, val networks: List<Network<*>>) {
}
}

override fun toString(): String {
return "NetworkCluster(uuid=$uuid, networks=$networks)"
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ class EnergyNetwork internal constructor(
private val EnergyHolder.fillFrac: Double
get() = energy.toDouble() / maxEnergy.toDouble()

override fun toString(): String {
return "EnergyNetwork(nodes=$nodes)"
}

companion object {

private val ENERGY_NETWORK = MAIN_CONFIG.node("network", "energy")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class FluidNetwork internal constructor(
}
}

override fun toString(): String {
return "FluidNetwork(nodes=$nodes)"
}

companion object {

private val FLUID_NETWORK = MAIN_CONFIG.node("network", "fluid")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class ItemNetwork internal constructor(
} while (transfersLeft != 0 && nextChannel != startingChannel)
}

override fun toString(): String {
return "ItemNetwork(nodes=$nodes)"
}

companion object {

private val ITEM_NETWORK = MAIN_CONFIG.node("network", "item")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,14 @@ class NetworkState internal constructor(
if (!file.exists())
return null

val network = file.inputStream().buffered().use { inp ->
val reader = ByteReader.fromStream(inp)
ProtoNetwork.read(networkId, world, this, reader)
try {
return file.inputStream().buffered().use { inp ->
val reader = ByteReader.fromStream(inp)
ProtoNetwork.read(networkId, world, this, reader)
}
} catch (e: Exception) {
throw Exception("Failed to load network from file $file", e)
}

return network
}

/**
Expand Down

0 comments on commit f76d63b

Please sign in to comment.