From 96a3246d1ed98ee3a22d97abae8016144c6a4b21 Mon Sep 17 00:00:00 2001 From: Ivan Pereira <183991+ivanrvpereira@users.noreply.github.com> Date: Sat, 21 Mar 2026 21:28:51 +0000 Subject: [PATCH] fix(search): restore error rendering and safe error handling - Re-add isError flag to error details so renderPerplexityResult shows error styling instead of green success rows - Use errorMessage() for unknown errors instead of unsafe cast - Trim whitespace-only PI_PERPLEXITY_MODEL env var values - Add comment explaining clearToken() on AUTH rejection --- src/config.ts | 2 +- src/index.ts | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/config.ts b/src/config.ts index 4fdf99e..61dd4f8 100644 --- a/src/config.ts +++ b/src/config.ts @@ -56,7 +56,7 @@ export function resolveSearchDefaults( params: { model?: string; incognito?: boolean }, config: PerplexityConfig, ): { model: string; incognito: boolean } { - const envModel = process.env.PI_PERPLEXITY_MODEL || undefined; + const envModel = process.env.PI_PERPLEXITY_MODEL?.trim() || undefined; const envIncognito = process.env.PI_PERPLEXITY_INCOGNITO || undefined; const model = params.model diff --git a/src/index.ts b/src/index.ts index d7182dc..b53d916 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,7 @@ import { formatForLLM } from "./search/format.js"; import { searchPerplexity } from "./search/client.js"; import { renderPerplexityCall } from "./render/call.js"; import { renderPerplexityResult } from "./render/result.js"; +import { errorMessage } from "./render/util.js"; import { AuthError, SearchError } from "./search/types.js"; export default function (pi: ExtensionAPI) { @@ -115,17 +116,18 @@ export default function (pi: ExtensionAPI) { if (error instanceof AuthError) { return { content: [{ type: "text", text: `Authentication failed: ${error.message}` }], - details: { sourceCount, queryMs }, + details: { sourceCount, queryMs, isError: true }, }; } if (error instanceof SearchError) { if (error.code === "AUTH") { + // Clear cached token on auth rejection so next call triggers re-login. await clearToken().catch(() => undefined); } return { content: [{ type: "text", text: `Perplexity search failed: ${error.message}` }], - details: { sourceCount, queryMs }, + details: { sourceCount, queryMs, isError: true }, }; } @@ -133,10 +135,10 @@ export default function (pi: ExtensionAPI) { content: [ { type: "text", - text: `Perplexity search failed: ${(error as Error).message || "Unknown error"}`, + text: `Perplexity search failed: ${errorMessage(error)}`, }, ], - details: { sourceCount, queryMs }, + details: { sourceCount, queryMs, isError: true }, }; } },