Skip to content

refactor(webview): extract shared safePostMessage helper#167

Open
mtskf wants to merge 5 commits into
mainfrom
chore/extract-safe-post-message
Open

refactor(webview): extract shared safePostMessage helper#167
mtskf wants to merge 5 commits into
mainfrom
chore/extract-safe-post-message

Conversation

@mtskf

@mtskf mtskf commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Summary

Consolidates ~9 near-identical webview→host postMessage try/catch blocks into one shared safePostMessage helper.

Changes

  • Add src/webview/safe-post-message.ts: safePostMessage(host, message, label, onError?) wraps the post + console.error("[quoll] postMessage(<label>) failed", err) and returns a success boolean; an optional onError hook lets a caller (e.g. postEditMessage) read the raw error for its own cleanup.
  • Migrate all 9 call sites to the helper: editor.ts (postEditMessage / postLintDiagnostics / postCaretReport), cm/context-handoff.ts (×2), cm/switch-editor.ts, cm/open-external.ts, cm/link-handlers.ts, cm/image/image-paste.ts.
  • Each call site keeps its own post-catch cleanup (dispatch serialize-error, clearPending, return value) — mechanical extraction only, no behaviour change. Log text is byte-identical.

Related

  • TODO: Extract a shared safePostMessage helper (webview) — simplification sweep 2026-07-10

Test Plan

  • pnpm compile — clean
  • pnpm test:unit — 3021/3021 passed
  • pnpm build + pnpm package + code --install-extension --force — installed and verified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant