microcks / microcks/microcks-cli

CLI crashes with panic if Microcks API returns unexpected responses

Open
#403 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
52
Forks
68
Avg merge
6h 54m
Merged PRs (30d)
10

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pkg/connectors/microcks_client.go by reviewing the client methods that read response bodies, unmarshal JSON, and use the id type assertion. Replace crash paths with returned, contextual errors and handle missing or invalid response fields; done means unexpected network, JSON, or response-shape errors reach the CLI as clean failures with a non-zero exit instead of a stack trace.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, cli, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
67/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.