log the failing command on a dispatch error (T-80)

The catch-all "dispatch threw" log omitted the request command, so a
handler exception couldn't be correlated to what caused it (PTY/IPC
audit item #26). Track the resolved cmd across the request handler and
include it in the error log.

The audit's other two items were already satisfied: errno/signal magic
numbers are centralized in PosixErrno + ffi/libc.dart, and the IPC
server already logs through the kernel Logger (no stderr.writeln left).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-10 16:59:09 +02:00
co-authored by Claude Opus 4.8
parent a7349aacf1
commit 66d3d024ca
3 changed files with 92 additions and 1 deletions
+6 -1
View File
@@ -190,6 +190,9 @@ class IpcServer {
final trimmed = line.trim();
if (trimmed.isEmpty) return;
IpcResponse response;
// Tracked across the try so a dispatch failure can be logged against the
// command that caused it, for log correlation (audit #26 / T-80).
var reqCmd = '?';
try {
final msg = IpcMessage.decode(trimmed);
if (msg is! IpcRequest) {
@@ -206,6 +209,7 @@ class IpcServer {
// streaming check sees the unwrapped command (T-129). Plain
// typed requests skip this path.
var req = msg;
reqCmd = req.cmd;
if (req.cmd == argvSentinelCmd) {
final result = unwrapArgvRequest(req);
if (result is ArgvError) {
@@ -220,6 +224,7 @@ class IpcServer {
return;
}
req = (result as ArgvParsed).request;
reqCmd = req.cmd;
}
if (_isTailSubscribe(req)) {
// Long-lived subscription branch (T-129). Send the streaming
@@ -240,7 +245,7 @@ class IpcServer {
),
);
} catch (e, st) {
log.error('ipc', 'dispatch threw', error: e, stackTrace: st);
log.error('ipc', 'dispatch threw for "$reqCmd"', error: e, stackTrace: st);
response = IpcResponse.err(
id: '',
error: IpcError(