Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate unknown onScanFailed error codes as IllegalStateExceptions #851

Merged
merged 2 commits into from
Feb 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}