Make write exceptions more descriptive
This commit is contained in:
parent
6b437b647d
commit
8e8f39bf33
2 changed files with 14 additions and 1 deletions
|
@ -0,0 +1,8 @@
|
|||
package eu.depau.etchdroid.exceptions
|
||||
|
||||
import eu.depau.etchdroid.kotlin_exts.toHRSize
|
||||
import java.io.IOException
|
||||
|
||||
class UsbWriteException(offset: Long, writtenBytes: Long, exc: Exception) : IOException(
|
||||
"Write failed at block $offset, ${writtenBytes.toHRSize()} written. Error: $exc", exc
|
||||
)
|
|
@ -5,6 +5,7 @@ import android.hardware.usb.UsbDevice
|
|||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import com.github.mjdev.libaums.UsbMassStorageDevice
|
||||
import eu.depau.etchdroid.exceptions.UsbWriteException
|
||||
import eu.depau.etchdroid.kotlin_exts.getFileName
|
||||
import eu.depau.etchdroid.kotlin_exts.name
|
||||
import java.io.BufferedInputStream
|
||||
|
@ -69,7 +70,11 @@ abstract class UsbApiWriteService(name: String) : UsbWriteService(name) {
|
|||
byteBuffer.limit(readBlocksBytes)
|
||||
|
||||
// Write the buffer to the device
|
||||
blockDev.write(offset, byteBuffer)
|
||||
try {
|
||||
blockDev.write(offset, byteBuffer)
|
||||
} catch (e: Exception) {
|
||||
throw UsbWriteException(offset, writtenBytes, e)
|
||||
}
|
||||
offset += (readBlocksBytes) / blockDev.blockSize
|
||||
writtenBytes += readBlocksBytes
|
||||
|
||||
|
|
Loading…
Reference in a new issue