← Back to Pull requests

TRT-2771: Return HTTP 400 for invalid filter fields instead of 500 #3739

Closed
unknown closed this pull request without merging on Jul 13, 2026 14:17 UTC
View on GitHub
unknown unknown commented on Jul 07, 2026 01:00 UTC
Author

Summary

  • Catches Postgres SQLSTATE 42703 (undefined column) and BigQuery HTTP 400 errors at the HTTP response boundary, returning 400 instead of 500

  • Fixes FilterOptionsFromRequest and ExtractFilters error responses from 500 to 400 across all handlers

  • Error details are logged server-side but not leaked to the client

  • Preserves error type chain through errors.Join so pgconn.PgError is detectable by errors.As at the boundary
  • Context

    API clients sending filter parameters with unrecognized column names (e.g., columnField: "component" on /api/tests) caused database errors surfaced as HTTP 500 responses. The database already validates column names, so we catch those errors at the boundary layer rather than maintaining a parallel field list.

    Follow-up

    Some pkg/api functions (e.g., PrintTestsJSONFromDB) write HTTP responses directly rather than returning errors to the sippyserver handler layer. This creates two parallel error response paths (RespondWithError vs failureResponseWithError). Unifying this by having all pkg/api functions return errors and letting sippyserver handle all HTTP responses is left for a follow-up refactor.

    Test plan

  • make lint passes

  • make test passes (14924 Go tests, 19 JS tests, 54 Python tests)

  • Manual: invalid filter field returns 400

  • Manual: valid filter field returns 200
  • Manual test evidence (against staging DB)

    Invalid filter field (component) on /api/tests returns 400:

    $ curl -s 'localhost:9090/api/tests?release=4.18&filter={"items":[{"columnField":"component","operatorValue":"equals","value":"test"}]}'
    {"code":400,"message":"error building test report"}
    

    Valid filter field (name) on /api/tests returns 200:

    $ curl -s 'localhost:9090/api/tests?release=4.18&filter={"items":[{"columnField":"name","operatorValue":"contains","value":"openshift-tests"}]}&limit=1' | python3 -c "import sys,json; d=json.load(sys.stdin); print(f'{len(d)} test(s) returned')"
    1 test(s) returned
    

    Invalid filter field (timestamp) on /api/jobs returns 400:

    $ curl -s 'localhost:9090/api/jobs?release=4.18&filter={"items":[{"columnField":"timestamp","operatorValue":"equals","value":"test"}]}'
    {"code":400,"message":"error building job report"}
    

    🤖 Generated with Claude Code

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    Summary by CodeRabbit

    Bug Fixes
    Improved API error handling so invalid request/filter parameters now return 400 Bad Request instead of server errors across multiple report and query endpoints.
    Standardized JSON error responses and messages for job, test, release, and pull request reporting, including clearer “build report” failures.
    Added consistent bad-request classification for PostgreSQL and BigQuery-style errors.
    Tests
    Added unit tests covering bad-request detection for PostgreSQL and Google API error variants.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 388 lines (+291 / -97) across 4 files Reviewer: sosiouxme Review duration: 9436m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.43) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 388 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.357
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3739"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 43.1% (MEDIUM) · Higher = larger blast radius
    43.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.6% · Safe to merge
    18.6%