Skip to content

fix(prometheus): a query that Prometheus refuses ends in a traceback #5487

Closed

Description

@dan-petty

Problem Description

devops prometheus query ends in a Python traceback when Prometheus refuses a query with HTTP 400. The local syntax check passes the query, so the server finds the error. The command prints HTTPStatusError: Client error '400 Bad Request' for url ... and does not print the error message of Prometheus, which tells what is wrong. The traceback also prints the full URL of the Prometheus host.

Reproduction Steps

  1. uv run devops prometheus query 'up * on (job) group_left (up == 1)'
  2. The command exits 1 with a 77-line traceback through src/devops_cli/commands/prometheus.py:144 (query) and src/devops_cli/prometheus/client.py:137 (_get_json).

Expected vs Actual Behavior

Expected: one error line with the error field of the Prometheus response (for example a parse error and its position), and exit code 1.

Actual: a traceback that ends in HTTPStatusError, with no message from Prometheus.

Environment Diagnostics

devops-cli from main on 2026-11-13.

Proposed Solution

Map an HTTP 4xx response of the Prometheus API to a DevOpsCLIError subclass that holds the errorType and the error fields of the JSON body, as the Prometheus HTTP API documents.

Acceptance Criteria

  • A test proves that a 400 response with an error field prints that error in one line and exits 1, with no traceback.

Related

Found while measuring docs/K8S_PERFORMANCE.md (#5444).

Activity

  1. added
    source/agent
    type/bug
    status/new
    value/medium
    effort/low
    on Nov 13, 2026
  2. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 13, 2026
  4. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor

    Delivered by #5549 (merged 2026-11-13). A Prometheus 400 now prints its errorType and error fields in one line, exits 1 and prints no traceback. Test: tests/commands/test_prometheus.py::test_a_query_that_prometheus_refuses_prints_its_error. The PR body named this issue with Refs only, because the readiness check refuses a body that closes two issues. The fix ships in the next release.

  5. removed
    status/new
    on Nov 13, 2026
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

    effort/lowpriority/p2-mediumsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions