microcks / microcks/microcks-cli
CLI crashes with panic if Microcks API returns unexpected responses
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 52
- Forks
- 68
- Ø Merge
- 6 Std. 54 Min.
- Gemergte PRs (30 T.)
- 10
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne in pkg/connectors/microcks_client.go mit der Überprüfung der Client-Methoden, die Response-Bodies lesen, JSON unmarshalen und die id-Typassertion verwenden. Ersetze Absturzpfade durch zurückgegebene, kontextbezogene Fehler und behandle fehlende oder ungültige Response-Felder; abgeschlossen ist dies, wenn unerwartete Netzwerk-, JSON- oder Response-Shape-Fehler die CLI als saubere Fehler mit einem Exit-Code ungleich null erreichen, statt eines Stacktraces.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- go
- Bereich
- api, cli, testing
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 67/100