Modern Apps git

← Modern-Apps.git

code: report shell start failure in terminal instead of crashing

Commit
1e279c2f32efe8bf93754f4fd831b37f1940c8d0
Author
Vayun Mathur <[email protected]>
When
2026-11-19 01:55 UTC (17 days ago)
Parents
c1a7c7e
startTerminal() constructs TerminalSession, whose init runs
ProcessBuilder(/system/bin/sh).directory(projectDir).start().
That throws IOException when the opened project folder has been
deleted or unmounted since it was opened (or the shell cannot be
executed).

Throw path: TerminalPage runs viewModel.startTerminal() from
LaunchedEffect, terminalSend() / terminalInterrupt() call it from
input handlers; none of them catch, so the IOException escaped
into composition / a click handler and crashed the app.

Fix: wrap the TerminalSession construction in runCatching inside
startTerminal; on failure append 'Could not start shell: ...' to
the terminal scrollback and leave the session stopped so a later
command retries.

Verification: ./gradlew :code:testDevUnitTest and ./check code
(run after this commit; see session report).

Diff

code/src/main/java/com/vayunmathur/code/platform/EditorTerminalOps.kt
diff --git a/code/src/main/java/com/vayunmathur/code/platform/EditorTerminalOps.kt b/code/src/main/java/com/vayunmathur/code/platform/EditorTerminalOps.ktindex 951b587910..ac1539f2a8 100644--- a/code/src/main/java/com/vayunmathur/code/platform/EditorTerminalOps.kt+++ b/code/src/main/java/com/vayunmathur/code/platform/EditorTerminalOps.kt@@ -10,16 +10,25 @@ fun EditorViewModel.startTerminal() {     // by a process that no longer exists. The identity check keeps a stale exit from a     // killed session (see terminalInterrupt) from clearing its replacement.     var session: TerminalSession? = null-    session = TerminalSession(-        dir = dir,-        onLine = { line -> appendTerminalLine(line) },-        onExit = {-            if (terminal === session) {-                terminal = null-                terminalRunning = false-            }-        },-    )+    // ProcessBuilder.start() throws IOException when the project folder was+    // deleted / unmounted after opening, or the shell cannot be executed.+    // Called from LaunchedEffect and click handlers, so an uncaught throw+    // here crashes the app; report it in the terminal instead.+    session = runCatching {+        TerminalSession(+            dir = dir,+            onLine = { line -> appendTerminalLine(line) },+            onExit = {+                if (terminal === session) {+                    terminal = null+                    terminalRunning = false+                }+            },+        )+    }.getOrElse { e ->+        appendTerminalLine("Could not start shell: ${e.message}")+        return+    }     terminal = session     terminalRunning = true }