Skip to content

Commit

Permalink
Propagate unknown onScanFailed error codes as `IllegalStateExceptio…
Browse files Browse the repository at this point in the history
…n`s (#851)
  • Loading branch information
twyatt authored Feb 7, 2025
1 parent 76f4b1b commit c756693
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions kable-core/src/androidMain/kotlin/scan/ScanError.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.bluetooth.le.ScanCallback.SCAN_FAILED_FEATURE_UNSUPPORTED
import android.bluetooth.le.ScanCallback.SCAN_FAILED_INTERNAL_ERROR
import android.bluetooth.le.ScanCallback.SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES
import android.bluetooth.le.ScanCallback.SCAN_FAILED_SCANNING_TOO_FREQUENTLY
import com.juul.kable.InternalError

@JvmInline
internal value class ScanError(internal val errorCode: Int) {
Expand All @@ -18,7 +17,7 @@ internal value class ScanError(internal val errorCode: Int) {
SCAN_FAILED_FEATURE_UNSUPPORTED -> "SCAN_FAILED_FEATURE_UNSUPPORTED"
SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES -> "SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES"
SCAN_FAILED_SCANNING_TOO_FREQUENTLY -> "SCAN_FAILED_SCANNING_TOO_FREQUENTLY"
else -> throw InternalError("Unsupported error code $errorCode")
else -> "UNKNOWN"
}.let { name -> "$name($errorCode)" }
}

Expand All @@ -43,5 +42,5 @@ internal val ScanError.message: String
SCAN_FAILED_SCANNING_TOO_FREQUENTLY ->
"Failed to start scan as application tries to scan too frequently"

else -> throw InternalError("Unsupported error code $errorCode")
else -> "Unknown scan error code: $errorCode"
}

0 comments on commit c756693

Please sign in to comment.