Skip to content

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

Open
Git-HimanshuRathi wants to merge 1 commit intomicrocks:masterfrom
Git-HimanshuRathi:fix/connectors-panic-to-error
Open

fix: return errors instead of panicking on response parsing in connectors#319
Git-HimanshuRathi wants to merge 1 commit intomicrocks:masterfrom
Git-HimanshuRathi:fix/connectors-panic-to-error

Conversation

@Git-HimanshuRathi
Copy link
Copy Markdown

@Git-HimanshuRathi Git-HimanshuRathi commented May 7, 2026

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
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

👋 @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 <[email protected]>
@Git-HimanshuRathi Git-HimanshuRathi force-pushed the fix/connectors-panic-to-error branch from 28fffb3 to 126f5dd Compare May 7, 2026 06:15
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

1 participant