microcks / microcks/microcks-cli

CLI crashes with panic if Microcks API returns unexpected responses

オープン
#403 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Go
スター
52
フォーク
68
平均マージ
6時間 54分
マージ済み PR(30日)
10

説明

While using the CLI, I noticed that pkg/connectors/microcks_client.go uses panic(err) in several places when reading HTTP response bodies or unmarshaling JSON.

If there is a temporary network glitch (e.g., the connection drops while reading the body) or if the Microcks server returns an invalid JSON response (like a 502 Bad Gateway HTML page from a proxy), the CLI will abruptly crash and print a Go stack trace instead of handling the error gracefully.

Additionally, methods like CreateTestResult use unsafe type assertions on the parsed JSON map (e.g., createTestResp["id"].(string)), which will also cause a panic if the id field is missing from the response payload.

Expected Behavior
The CLI should catch these errors, bubble them up through the standard error return values, and print a clean, user-friendly error message to the terminal before exiting with a non-zero status code.

Actual Behavior
The CLI completely crashes with a stack trace.

Suggested Fix
We should replace all instances of panic(err) in these client methods with proper context-wrapped errors (e.g., fmt.Errorf("failed to read response: %w", err)) since the functions already have an error return type defined. We should also add the comma-ok idiom to the type assertions to ensure we don't crash on missing fields.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

pkg/connectors/microcks_client.go から始めて、response body を読み取り、JSON をアンマーシャルし、id の型アサーションを使用している client メソッドを確認します。クラッシュする経路を、返却されるコンテキスト付きエラーに置き換え、欠落している、または無効な response フィールドを処理します。予期しないネットワーク、JSON、または response の形状に関するエラーが、stack trace ではなく、ゼロ以外の終了コードを伴う正常な失敗として CLI に到達すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
go
領域
api, cli, testing
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
67/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。