Skip to content

Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.

fix: surface a visible error when a picked file can't be opened

Rishabh Bajpai88210da40bcb
diff --git a/app/src/main/java/com/gotcha/agent/ChatViewModel.kt b/app/src/main/java/com/gotcha/agent/ChatViewModel.kt
index a23104b..2ee5e79 100644
--- a/app/src/main/java/com/gotcha/agent/ChatViewModel.kt
+++ b/app/src/main/java/com/gotcha/agent/ChatViewModel.kt
@@ -767,11 +767,15 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), A
try {
val resolver = getApplication<Application>().contentResolver
val mime = resolver.getType(uri)
- if (mime?.startsWith("image/") == true) {
+ val picked = if (mime?.startsWith("image/") == true) {
loadImageBase64(uri)?.let { PickedFile.Image(it) }
} else {
loadDocument(uri)?.let { PickedFile.Document(it) }
- } to null
+ }
+ // Both loaders return null when the stream cannot be opened;
+ // treat that like any other failed pick so the user gets a
+ // visible error instead of a silent no-op.
+ if (picked != null) picked to null else null to "Could not read that file."
} catch (e: CancellationException) {
throw e
} catch (e: DocumentError) {
diff --git a/app/src/test/java/com/gotcha/agent/ChatViewModelAttachmentTest.kt b/app/src/test/java/com/gotcha/agent/ChatViewModelAttachmentTest.kt
index a3b69b2..61197e8 100644
--- a/app/src/test/java/com/gotcha/agent/ChatViewModelAttachmentTest.kt
+++ b/app/src/test/java/com/gotcha/agent/ChatViewModelAttachmentTest.kt
@@ -113,8 +113,9 @@ class ChatViewModelAttachmentTest {
@Test
fun `pickContent parses off the caller thread and delivers on pickResults`() {
// A content URI with no provider behind it: the stream can't open, so the
- // pick resolves to null. The point is the plumbing — nothing may happen on
- // the calling thread, and the result arrives asynchronously via pickResults.
+ // pick resolves to null and a visible error bubble is appended. The point
+ // is the plumbing — no work may run on the calling thread, and the result
+ // arrives asynchronously via pickResults.
val uri = Uri.parse("content://com.gotcha.missing.provider/attachments/missing.pdf")
viewModel.pickContent(uri)
@@ -134,6 +135,10 @@ class ChatViewModelAttachmentTest {
collector.cancel()
assertNull("pick should resolve to null, got $result", result)
+ // The failed pick is never silent: an error bubble explains it in the chat.
+ val error = viewModel.uiState.value.messages.lastOrNull()
+ assertEquals(MessageKind.ERROR, error?.kind)
+ assertTrue(error?.text?.contains("Could not read that file") == true)
}
@Test