Log server errors on the public API 500 paths (wire tracing in the api crate) #18

Closed
opened 2026-06-02 12:06:18 +00:00 by logaritmisk · 1 comment
Owner

Context

The public API handlers (crates/api/src/public.rs) map db errors to 500 via .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR) / Err(_) => INTERNAL_SERVER_ERROR, discarding the underlying sqlx::Error. A 500 with no trace makes production debugging hard. The api crate currently has no tracing dependency (the server crate does).

What to do

  • Add tracing to the api crate.
  • Log the discarded error on every 500 path, e.g.:
    .map_err(|err| { tracing::error!(?err, "db error listing public objects"); StatusCode::INTERNAL_SERVER_ERROR })
    
  • Apply consistently across list_objects and get_object (and future handlers).

References

  • crates/api/src/public.rslist_objects, get_object
  • Surfaced by the Plan 7 Task 3 code-quality review.
## Context The public API handlers (`crates/api/src/public.rs`) map db errors to `500` via `.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)` / `Err(_) => INTERNAL_SERVER_ERROR`, **discarding the underlying `sqlx::Error`**. A 500 with no trace makes production debugging hard. The `api` crate currently has no `tracing` dependency (the `server` crate does). ## What to do - Add `tracing` to the `api` crate. - Log the discarded error on every 500 path, e.g.: ```rust .map_err(|err| { tracing::error!(?err, "db error listing public objects"); StatusCode::INTERNAL_SERVER_ERROR }) ``` - Apply consistently across `list_objects` and `get_object` (and future handlers). ## References - `crates/api/src/public.rs` — `list_objects`, `get_object` - Surfaced by the Plan 7 Task 3 code-quality review.
Author
Owner

Scope note from the admin-CRUD work (merged main @ c4e0c4c): the new admin handlers follow the same pattern as the public surface — .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR) with the underlying error discarded and no tracing. This affects crates/api/src/admin_objects.rs, admin_vocab.rs, and admin_authorities.rs. When wiring tracing, cover the whole api crate's 500 paths, not just the public endpoints.

Scope note from the admin-CRUD work (merged `main` @ `c4e0c4c`): the new admin handlers follow the same pattern as the public surface — `.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)` with the underlying error discarded and no tracing. This affects `crates/api/src/admin_objects.rs`, `admin_vocab.rs`, and `admin_authorities.rs`. When wiring tracing, cover the whole `api` crate's 500 paths, not just the public endpoints.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: logaritmisk/biggus-dickus#18