Skip to content

Sanitise trino errors - #430

Merged
Bohreromir merged 4 commits into
mainfrom
worktree-fix-304-sanitise-trino-errors
Nov 3, 2026
Merged

Bohreromir merged 4 commits into
mainfrom
worktree-fix-304-sanitise-trino-errors

Conversation

@Bohreromir

@Bohreromir Bohreromir commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Description

This classifies Trino errors and passes some to the user and keeping potentially sensitive ones to the server while informing the user generic

closes #304

Docs

Release note

Checklist

Author

  • AI review done, findings addressed
  • Tests added or updated
  • Changelog updated (if the repo keeps one)

Reviewer

  • Useful comments and logging
  • Docs added or updated per the style guide

Acceptance

  • Check for release notes and docs

Trino error messages and raw upstream response bodies were passed to the
browser verbatim. Errors are now classified on the server:

- USER_ERROR and INSUFFICIENT_RESOURCES keep Trino's message, as they
  describe the user's own query.
- INTERNAL_ERROR, EXTERNAL and unknown types only expose the error name;
  the message is logged.
- HTTP and network failures are reported as unavailable; the response
  body is only logged.

Query snapshots carry the classification as a structured error that the
client translates. The catalog and completion metadata endpoints return
a generic message with the request ID for anything but query errors.
Add mock Trino markers for an internal error and an HTTP 502 while
polling, and check that the UI shows the generic text without the
internal details.
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 67.49% 9183 / 13605
🔵 Statements 66.45% 12363 / 18604
🔵 Functions 68.27% 2965 / 4343
🔵 Branches 57.42% 5177 / 9015
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/lib/components/trino/StatementResult.svelte 0% 0% 0% 0% 27-282
src/lib/server/trino/client.ts 67.12% 61.29% 53.33% 73.43% 74, 75, 87-88, 108, 126-136, 150, 160, 185-191, 223-224, 230, 266-273
src/lib/server/trino/errors.ts 100% 90% 100% 100%
src/lib/server/trino/queries.ts 100% 93.63% 100% 100%
src/lib/server/trino/result-collector.ts 89.79% 73.07% 100% 95.65% 25, 31, 40, 45, 87
src/lib/types/query.ts 100% 100% 100% 100%
src/routes/(app)/api/trino/catalog/+server.ts 100% 100% 100% 100%
src/routes/(app)/api/trino/completion/metadata/+server.ts 100% 100% 100% 100%
src/routes/(app)/trino/+page.svelte 0% 0% 0% 0% 396-788
Generated in workflow #1238 for commit d8eac13 by the Vitest Coverage Report Action

@Bohreromir
Bohreromir marked this pull request as ready for review October 29, 2026 15:34
@Bohreromir Bohreromir self-assigned this Oct 29, 2026
@Bohreromir Bohreromir moved this to Development: Waiting for Review in Stackable Engineering Oct 29, 2026
@adwk67
adwk67 self-requested a review November 2, 2026 14:37
@adwk67 adwk67 moved this from Development: Waiting for Review to Development: In Review in Stackable Engineering Nov 2, 2026
adwk67
adwk67 previously approved these changes Nov 2, 2026

@adwk67 adwk67 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: if the config contains a wrong password, the server logs a 401 internally

    [16:39:29.394] ERROR: failed to submit statement in script
        service: "stackable-cockpit"
        module: "trino-queries"
        user_id: "oYdJDHf0VhTXnqHN8tzT5cVkT03NuYgV"
        tab_id: "d3c19c72-0a47-4276-8585-ef529b9a3859"
        err: {
          "type": "TrinoHttpError",
          "message": "Trino POST /v1/statement failed (401)",
          "stack":
              TrinoHttpError: Trino POST /v1/statement failed (401)
                  at TrinoClient.submit (/home/andrew/gitrepos/cockpit/src/lib/server/trino/client.ts:60:13)
                  at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
                  at async submitStatement (/home/andrew/gitrepos/cockpit/src/lib/server/trino/queries.ts:126:20)
                  at async runStatements (/home/andrew/gitrepos/cockpit/src/lib/server/trino/queries.ts:201:15)
                  at async startScript (/home/andrew/gitrepos/cockpit/src/lib/server/trino/queries.ts:191:5)
          "status": 401,
          "body": "Access Denied: Invalid credentials",
          "name": "TrinoHttpError"
        }

but then never gets out of a loop on

  [16:39:29.613] TRACE: Request started
      service: "stackable-cockpit"
      request_id: "81043d6e-5a62-4b2f-80d7-7a787f61083d"
      method: "GET"
      path: "/api/trino/query"
  [16:39:29.615] TRACE: query poll
      service: "stackable-cockpit"
      request_id: "81043d6e-5a62-4b2f-80d7-7a787f61083d"
      method: "GET"
      path: "/api/trino/query"
      user_id: "oYdJDHf0VhTXnqHN8tzT5cVkT03NuYgV"
      tab_id: "d3c19c72-0a47-4276-8585-ef529b9a3859"
      count: 0
  [16:39:29.615] TRACE: Request completed
      service: "stackable-cockpit"
      request_id: "81043d6e-5a62-4b2f-80d7-7a787f61083d"
      method: "GET"
      path: "/api/trino/query"
      status_code: 200
      duration_ms: 1

and the editor is stuck on "Running...". This might also happen if Trino happens to be unavailable the moment someone clicks on "Run" (though I haven't tested that).

Can we improve on the error feedback in this case? (According to Claude this is the same on main, so not strictly something to do with this PR).

Comment thread src/lib/server/trino/errors.ts Resolved
labrenbe
labrenbe previously approved these changes Nov 2, 2026

@labrenbe labrenbe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

…tise-trino-errors

# Conflicts:
#	src/lib/server/trino/client.ts
#	src/lib/server/trino/queries.ts
A submit that Trino rejected stored nothing for the tab, so the browser
kept polling an empty list and the editor stayed on "Running...". The
failed statement is now stored as FAILED with the classified error.

HTTP 401 and 403 from Trino get their own error kinds instead of being
reported as unavailable. For 401 the message depends on where the
credentials come from: the deployment configuration (contact an
administrator) or the user's own connection (check the settings).
@Bohreromir
Bohreromir dismissed stale reviews from labrenbe and adwk67 via d8eac13 November 3, 2026 11:10

@adwk67 adwk67 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Bohreromir
Bohreromir added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit cfa0962 Nov 3, 2026
18 of 20 checks passed
@Bohreromir
Bohreromir deleted the worktree-fix-304-sanitise-trino-errors branch November 3, 2026 12:05
@Bohreromir Bohreromir moved this from Development: In Review to Development: Done in Stackable Engineering Nov 3, 2026
@Bohreromir Bohreromir linked an issue Nov 3, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Development: Done

Development

Successfully merging this pull request may close these issues.

Failed trino statement submit is not reported Raw upstream error messages returned to the client

3 participants