microcks-cli icon indicating copy to clipboard operation
microcks-cli copied to clipboard

fix(connectors): replace panics with error returns and add HTTP status code validation

Open gyanranjanpanda opened this issue 6 months ago • 3 comments

Summary

Fixes #401 - Six methods across pkg/connectors/microcks_client.go and pkg/connectors/keycloak_client.go previously crashed with Go panics when receiving non-2xx HTTP responses. This PR replaces all panic() calls with proper error returns and adds HTTP status code validation before JSON parsing.

Changes

pkg/connectors/microcks_client.go

  • GetKeycloakURL: Add status check, replace panics, use comma-ok assertions. Return "null" early when Keycloak disabled.
    • CreateTestResult: Add status check, replace panics, guard id extraction.
    • GetTestResult: Add status check, replace panic. Prevents silent false test failures.
    • DownloadArtifact: Replace remaining ReadAll panic.
    • redeemRefreshToken: Replace errors.CheckError() with proper error returns.

pkg/connectors/keycloak_client.go

  • ConnectAndGetToken: Add status check, replace panics, guard access_token.
    • GetOIDCConfig: Add status check, replace panics, guard assertions, fix swallowed error.
    • ConnectAndGetTokenAndRefreshToken: Add status check, replace panics, guard assertions, fix swallowed error.

Tests (18 new)

  • microcks_client_error_test.go: 16 tests for non-2xx, malformed JSON, missing fields, disabled Keycloak, redeemRefreshToken.
    • keycloak_client_test.go: 7 tests covering all Keycloak client error paths.

gyanranjanpanda avatar May 17 '26 17:05 gyanranjanpanda

👋 @gyanranjanpanda

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!

github-actions[bot] avatar May 17 '26 17:05 github-actions[bot]

@Harsh4902 could u review this

gyanranjanpanda avatar May 23 '26 09:05 gyanranjanpanda

@Harsh4902 could u review this now

gyanranjanpanda avatar May 26 '26 01:05 gyanranjanpanda