Skip to content

fix: return errors instead of panicking on response parsing in connectors - #319

Closed
Heyy-Himanshuu wants to merge 1 commit into
microcks:masterfrom
Heyy-Himanshuu:fix/connectors-panic-to-error
Closed

fix: return errors instead of panicking on response parsing in connectors#319
Heyy-Himanshuu wants to merge 1 commit into
microcks:masterfrom
Heyy-Himanshuu:fix/connectors-panic-to-error

Conversation

@Heyy-Himanshuu

@Heyy-Himanshuu Heyy-Himanshuu commented May 7, 2026

Copy link
Copy Markdown

Summary

Replaces 12 panic(err) / panic(err.Error()) calls in pkg/connectors/{microcks,keycloak}_client.go with wrapped fmt.Errorf("...: %w", err) returns.
Cleans up three return x, err sites where err was guaranteed nil after the change (now return x, nil).
Continues the pattern established by #258, #259 and commit f9f282c, which fixed the same anti-pattern in one location each.
fixes #318

Why

Every affected method already returns error. Panicking on io.ReadAll / json.Unmarshal / io.Copy failure means a malformed or truncated response from Microcks/Keycloak crashes the CLI with a stack trace instead of surfacing a clean error. This is most visible when a reverse proxy or gateway returns HTML on an otherwise-2xx request, or when the connection drops mid-body.

Test plan

  • go build ./... passes
  • go test ./pkg/connectors/... passes (existing TestDownloadArtifactReturnsResponseBody still green)
  • Manual: point CLI at a server returning HTML on /api/keycloak/config — previously panicked, now returns a wrapped error

@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown

👋 @Git-HimanshuRathi

Welcome to the Microcks community! 💖

Thanks and congrats 🎉 for opening your first pull request here! Be sure to follow the pull request template or please update it accordingly.

Hope you have a great time there!

…tors

Replace panic(err) / panic(err.Error()) calls in microcks_client.go and
keycloak_client.go with wrapped fmt.Errorf returns. All affected methods
already declared error in their return signature, so panicking on
io.ReadAll, json.Unmarshal, or io.Copy failure crashed the CLI instead
of surfacing a clean error to the user.

Continues the pattern from microcks#258, microcks#259, and f9f282c.

Signed-off-by: Git-HimanshuRathi <himanshurathiwork@gmail.com>
@Caesarsage

Copy link
Copy Markdown
Contributor

as per my comments here: #318 (comment)

I believe this can be closed

@Harsh4902 Harsh4902 closed this Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace panic() with error returns in connectors package

3 participants