Skip to content

ApiError::query returns 500 for caller errors: audit its callers onto invalid_query #1908

Open

Description

@bplatz

Summary

ApiError::query(msg) (fluree-db-api/src/error.rs) builds ApiError::Internal("Query error: …"), which both ApiError::status_code() and the server's ServerError::status_code() map to 500. Despite the name, it's used mostly for errors caused by the caller: a bad selector, an unknown graph, invalid options. Clients that retry on 5xx treat those as server faults, and so do operators watching err:system/InternalError.

#1896 added ApiError::invalid_query(msg) (QueryError::InvalidQuery, a 400). Only the new time-pin refusals use it so far, plus the dataset-spec parse errors, which #1897 moved over. There are still 79 ApiError::query( calls across 19 files in fluree-db-api/src. The largest groups:

File Calls
query/connection.rs 14
policy_builder.rs 13
ledger_view.rs 9
query/builder.rs 8
view/query.rs, query/nameservice_builder.rs 4 each

Proposal

Audit each call site and sort it into one of two groups:

  • Caller errors → invalid_query (400): for example unknown named graph, missing ledger before #, and commit-prefix-not-found in time_resolve.
  • Genuine internal failures → ApiError::internal (500), stated explicitly.

Then either delete ApiError::query or rename it, so the name no longer suggests a 400. Each converted site should get a status_code() assertion in its test.

Changing the constructor itself to a 400 in one step is tempting, but it would also turn any real internal failure among the callers into a 400. The audit is the point.

Follow-up to review feedback on #1896.

Activity

  1. added
    P3
    area:query
    on Sep 22, 2026
  2. bplatz commented on Sep 23, 2026

    @bplatz
    ContributorAuthor

    placeholder

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

    P3area:query

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions