#4784: fix(imessage): handle non-JSON output from imsg CLI gracefully
channel: imessage
Cluster:
Error Handling Improvements
Fixes #4707
## Problem
When the CLI encounters errors (e.g., permission denied accessing chat.db), it outputs plain-text error messages to stdout instead of properly formatted JSON-RPC responses. This causes the RPC client to fail parsing and log overwhelming error messages like:
```
msg rpc: failed to parse permissionDenied(path: "/Users/.../chat.db", underlying: authorization denied (code: 23)): Unexpected token 'p', "permission"... is not valid JSON
```
## Solution
This fix improves error handling in the RPC client:
- Adds explanatory comments about why non-JSON output can occur
- Truncates long lines in error messages (max 200 chars) to prevent log spam
- Improves error message clarity: "received non-JSON output" instead of "failed to parse"
- Removes unused error detail variable
## Testing
- Linter passed with no errors
- Change is backward compatible (only affects error handling)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates `IMessageRpcClient`'s stdout line handling to better cope with cases where the `imsg rpc` CLI prints plain-text errors to stdout instead of JSON-RPC. In `src/imessage/client.ts`, parse failures now produce a clearer log message and the logged line is truncated to avoid log spam, while removing an unused error-detail variable.
This fits into the existing client flow where stdout is treated as a JSON-RPC stream (`handleLine`) and stderr is already logged line-by-line; the change only affects how stdout parse errors are reported and does not alter request/response handling for valid JSON-RPC frames.
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge with low risk; it only changes logging/error reporting around stdout parse failures.
- The change is localized to `handleLine`’s JSON.parse error path and does not affect normal JSON-RPC request/response routing. Main remaining concern is reduced diagnosability because the parse error is swallowed, but functionality should be unchanged for valid JSON.
- src/imessage/client.ts (only for log/debuggability expectations)
<!-- greptile_other_comments_section -->
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#23161: fix(imessage): parse permission denied errors from imsg rpc plainte...
by NewdlDewdl · 2026-02-22
81.1%
#2744: FIX(imessage): preserve signal info in RPC close handler
by sal-jim · 2026-01-27
78.7%
#18664: fix(imessage): honor groupConfig regardless of allowlistEnabled
by brandonwise · 2026-02-16
75.8%
#23724: fix(security): sanitize RPC error messages in signal and imessage c...
by kevinWangSheng · 2026-02-22
74.9%
#9173: Fix: Improve error messaging for API rate limits and billing errors
by vishaltandale00 · 2026-02-04
74.7%
#5693: fix(chat): display error messages when LLM requests fail
by niemesrw · 2026-01-31
74.5%
#4878: fix: string/type handling and API fixes (#4537, #4380, #4373, #4547...
by lailoo · 2026-01-30
74.4%
#8175: fix: suppress raw API errors for non-owners
by Rakshi2609 · 2026-02-03
73.4%
#7353: fix: prevent silent message drops after config.patch restart
by 18-RAJAT · 2026-02-02
73.0%
#13881: fix: Address Greptile feedback - test isolation and channel resolution
by trevorgordon981 · 2026-02-11
72.7%