Skip to content

Uncontrolled Panics in API Client on Unexpected Server Responses #478

Description

@aniket866

Describe the bug

Description

In pkg/connectors/microcks_client.go, functions like GetKeycloakURL and GetTestResult use panic(err) or panic(err.Error()) if response body reading or JSON deserialization fails.

Impact

If a reverse proxy, API gateway, or cloud load balancer returns an HTML error page (e.g., 502 Bad Gateway, 504 Gateway Timeout, 403 Forbidden) instead of valid JSON, the CLI crashes with a Go stack trace instead of presenting a clean error message to the user.

Code Reference

  • pkg/connectors/microcks_client.go
  • pkg/connectors/microcks_client.go

Diagram

sequenceDiagram
    participant CLI
    participant Proxy as Reverse Proxy (Nginx/Cloudflare)
    participant Server as Microcks Server
    CLI->>Proxy: GET /api/keycloak/config
    Proxy--xServer: Connection Refused / Timeout
    Proxy-->>CLI: HTTP 504 Gateway Timeout (HTML body)
    Note over CLI: io.ReadAll() succeeds but JSON parsing fails
    Note over CLI: json.Unmarshal(body, &configResp) errors out
    CLI->>CLI: panic(err) (Hard crash with stack trace)
Loading

Steps to Reproduce

  1. Target a server address that serves non-JSON content (e.g., any public landing page returning HTML).
  2. Run microcks login <URL>.
  3. The client fails to unmarshal the HTML body and crashes with panic: invalid character '<' looking for beginning of value.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleState due to inactivity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions