Skip to content

Uncontrolled Panics in API Client on Unexpected Server Responses #478

Closed

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

  1. github-actions commented on Jul 30, 2026

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity 😴

    It will be closed in 30 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

    There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. Microcks is a Cloud Native Computing Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

    Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

    Thank you for your patience ❤️

  2. added
    stale
    on Jul 30, 2026
  3. Caesarsage commented on Aug 16, 2026

    @Caesarsage
    Collaborator

    This is resolved on current master: all panic() calls were removed from pkg/connectors in #489. Response-body read and JSON decode failures now return classified errors (KindAPI / KindConnection) instead of crashing, and HTTP status codes are validated before parsing — the HTML-error-page-from-a-proxy case is covered by tests like TestGetFullTestResultChecksStatusBeforeParsing. I believe this can be closed.

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

    stale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions