feat: add shared messaging utils and surface real Claude CLI errors#58
Open
sean808080 wants to merge 1 commit intomoazbuilds:masterfrom
Open
feat: add shared messaging utils and surface real Claude CLI errors#58sean808080 wants to merge 1 commit intomoazbuilds:masterfrom
sean808080 wants to merge 1 commit intomoazbuilds:masterfrom
Conversation
Claude CLI exits non-zero on auth and quota failures, but the human-readable message (e.g. "Not logged in · Please run /login") lives in the JSON stdout `result` field, not stderr. All three chat bridges (start.ts, telegram.ts, discord.ts) were showing "Unknown error" instead of the actual message. This PR introduces src/messaging.ts with shared utility functions: - extractErrorDetail(): prefers stderr, falls back to parsing JSON stdout for Claude CLI's is_error/result error pattern - describeProvider(): human-readable provider/model label - isProviderStatusQuery() / isModelChangeRequest(): intent detection - authoritativeProviderReply(): canonical provider status response - extractReactionDirective(): strips [react:emoji] directives from text Updates start.ts, telegram.ts, and discord.ts to use extractErrorDetail so auth failures, quota errors, and other CLI failures show the real error message across all chat interfaces.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Claude CLI exits non-zero on auth and quota failures, but the human-readable error message (e.g.
Not logged in · Please run /login) lives in the JSON stdoutresultfield — not in stderr. All three chat bridges were showingUnknown errorinstead of the actual failure reason.Before:
After:
Solution
Introduces
src/messaging.ts— a shared utilities module used bystart.ts,telegram.ts, anddiscord.ts.Key function:
extractErrorDetail(result)Additional utilities (no behaviour change, available for future use)
describeProvider()— human-readable provider/model labelisProviderStatusQuery()/isModelChangeRequest()— intent detection for model-switch queriesauthoritativeProviderReply()— canonical provider status responseextractReactionDirective()— strips[react:emoji]directives from response textFiles changed
src/messaging.tssrc/commands/start.tsextractErrorDetailinforwardToTelegramandforwardToDiscordsrc/commands/telegram.tsextractErrorDetailin the main message handler error pathsrc/commands/discord.tsextractErrorDetailin the main message handler error pathTesting
Auth failures now surface the real Claude CLI message across all three chat interfaces. The fix handles:
stderrpresent → returns stderr (existing behaviour, unchanged)stderrempty, JSON stdout withis_error: true→ returnsresultfieldstderrempty, JSON stdout witherror.message→ returnserror.message