Skip to content

bug: nil error logged on non-OK HTTP response in probe agent registerServer #785

@coderabbitai

Description

@coderabbitai

Description

In internal/probe/probe.go, the registerServer function logs a nil err when the HTTP registration response has a non-OK status code.

When c.Do(req) succeeds (i.e., a response is received), err is nil. However, if resp.StatusCode is neither http.StatusOK nor http.StatusCreated, the current code calls:

a.log.Error(err, "Failed to register server", "url", a.RegistryURL)

Since err is nil here, the log entry loses all meaningful failure context (status code, response body, etc.).

Expected Behavior

The log should include a concrete error describing the failure, e.g. the HTTP status code and/or response body, so operators can diagnose registration failures.

Suggested Fix

bodyBytes, _ := io.ReadAll(resp.Body)
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
    a.log.Error(
        fmt.Errorf("unexpected response status: %d", resp.StatusCode),
        "Failed to register server",
        "url", a.RegistryURL,
        "statusCode", resp.StatusCode,
        "responseBody", string(bodyBytes),
    )
    return false, nil
}

References

/cc @afritzler

Metadata

Metadata

Assignees

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions