microcks / microcks/microcks-cli

Replace panic() with error returns in connectors package

Open
#318 3 comments 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

### Bug description
Several methods in pkg/connectors/microcks_client.go and pkg/connectors/keycloak_client.go call panic() when io.ReadAll or json.Unmarshal fail on an HTTP response. Because every one of these methods already has error in its return signature, panicking instead of returning the error means any malformed/truncated response from the Microcks server or Keycloak crashes the entire CLI with a stack trace, instead of producing a clean user-facing error.

This is the same anti-pattern that was previously fixed in:

[#258](https://github.com/microcks/microcks-cli/pull/258) (json.Unmarshal ignored in GetTestResult)
[#259](https://github.com/microcks/microcks-cli/pull/259) (DownloadArtifact not reading body)
f9f282c (replaced one panic in GetTestResult with a wrapped error)
The recent f9f282c only fixed a single occurrence. The same panic(err) / panic(err.Error()) pattern still exists in 11 other places.

### Reproduction
Any scenario where the Microcks or Keycloak server returns a non-JSON body (HTML error page from a reverse proxy, truncated body on connection drop, gateway timeout HTML, etc.) on an otherwise-2xx-coded request will crash the CLI with a Go panic stack trace instead of a friendly error.

### Proposed fix
Replace each panic(err) / panic(err.Error()) with a wrapped fmt.Errorf("...: %w", err) return, matching the style of the recent fix at microcks_client.go:413-415.

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 and pkg/connectors/keycloak_client.go, using the existing fix around microcks_client.go:413-415 as the reference and locating the remaining panic(err) and panic(err.Error()) calls. Review the affected methods' error returns and run the connectors package tests. Done means all 11 response-reading and JSON-decoding failures return wrapped errors instead of panicking.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.