Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

onMessage calls the callback twice, with the raw string, when the callback throws

未關閉 適合新手
#502 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 3 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
85/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
react-native, typescript
領域
mobile

研究方向

從 packages/react-native-brownfield/src/index.ts 中的 ReactNativeBrownfield.onMessage 開始,檢查解析錯誤和回呼錯誤的處理方式。使用一則有效的 JSON 訊息和一個會丟出錯誤的回呼來重現;完成的標準是回呼使用解析後的資料執行一次,且其原始錯誤會浮現。

由索引模型根據 Issue 內容生成。

描述

ReactNativeBrownfield.onMessage in packages/react-native-brownfield/src/index.ts calls the callback inside the same try block as JSON.parse:

try {
  callback({ data: JSON.parse(payload.text) });
} catch {
  callback({ data: payload.text });
}

If the callback throws while it handles a valid JSON message, the catch branch runs the callback again with the unparsed string as data, and the original error is discarded.

Steps to reproduce

  1. Subscribe with a callback that throws, for example ReactNativeBrownfield.onMessage(() => { throw new Error('boom'); }).
  2. From the native host, post a JSON message such as {"type":"login"}.

Expected behavior

The callback runs once with data set to { type: 'login' }, and the boom error surfaces.

Actual behavior

The callback runs twice: first with { type: 'login' }, then with the string '{"type":"login"}'. The boom error from the first call is swallowed. Handlers that are not idempotent run their side effects twice, and the second call usually fails with a different, misleading error.

主要語言
TypeScript
星號
552
分支
53
平均合併
3 天 8 小時
30 天內合併 PR
23

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

callstack/react-native-brownfield 的其他 Issue

查看 callstack/react-native-brownfield 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。