feat: checks keep error details and stack traces

Merged
EV
2d ago
+417-43

Description

Third backend PR for the connector checks redesign, stacked on #16157. A check that did not pass now keeps what the form's Error Details and Stack Trace need, beyond its message.

  • error_detail on each FAILED or INCOMPLETE result (models.py:CheckErrorDetail):

    • the HTTP status;
    • the request, as method, host and path only. The query string and user info are dropped, because they can hold secrets;
    • a response excerpt of at most 500 characters.

    These come from the first SourceApiError or requests.HTTPError in the exception chain, so a mapped error such as InsufficientPermissionsError(...) from http_error keeps its response.

  • Redaction. URL query strings, and every credential value of the run (scrub_sensitive_values), are removed from the response excerpt and the stack trace. A requests error's message holds the full URL, and the trace prints it. The legacy blocking-validation recorder has no credential at hand, so it stores no details.

  • Stack trace (at most 4000 characters, the tail) only when the cause is unknown: a timeout, an unreachable source or an unexpected error. A known cause (rejected, permission, invalid, rate limited) has none, as the design says.

  • SourceApiError (connectors/exceptions.py) is the base of a source gateway's API errors: status, method, URL and body. JiraApiError subclasses it, and its text attribute is now body. Confluence raises requests errors, which the chain already covers. The other gateways move to the base in their own PRs.

  • The detail is carried through:

    • draft states and the draft result cache;
    • stored reports (additive JSONB, no migration);
    • the blocking-validation recorder.

Verified on a local stack: a Confluence draft run with a wrong token gives the sign-in row status_code: 403, request: "GET danswerai.atlassian.net/wiki/rest/api/space" and Atlassian's error body. The redesigned rows that show this are the frontend owner's work.

How Has This Been Tested?

  • New unit tests (test_check_error_details.py):
    • a mapped requests error keeps its response but not the query;
    • a SourceApiError response is bounded;
    • a stack trace only for an unknown cause;
    • no detail for a known cause without a response;
    • credential values (nested ones too) and URL queries are redacted.
  • Jira unit tests updated for body. Connector and EE unit tests: 4269 passed.
  • The 93 capability-check external dependency tests pass on a scratch DB.
  • A local ods stack run, as described above.

Additional Options

  • [Optional] Please cherry-pick this PR to the latest release version.
  • [Optional] Override Linear Check

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Failed connector capability checks now include diagnostic details, such as HTTP status, request information, and a response excerpt. Unexpected errors can include a stack trace.
    • Sensitive values and URL query strings are redacted, and diagnostic details are limited in length.
  • Bug Fixes
    • Jira error messages and related details are now read consistently from the response body.