sqlx-errors

Map sqlx::Error variants to typed AppError responses with cross-database-safe checks.

Updated May 26, 2026
One-click install
npx skills add https://github.com/adelabdelgawad/rust-fullstack-agents --skill sqlx-errors
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sqlx-errors
Source: https://github.com/adelabdelgawad/rust-fullstack-agents/tree/main/plugins/rusty/skills/sqlx-errors
Command: npx skills add https://github.com/adelabdelgawad/rust-fullstack-agents --skill sqlx-errors

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Map sqlx::Error variants to typed AppError responses while avoiding leaking raw error strings to API clients.

Core Features & Use Cases

  • Cross-database-safe error classification using DatabaseError trait methods (is_unique_violation, is_foreign_key_violation, is_check_violation).
  • Comprehensive mappings from common sqlx errors (RowNotFound, DatabaseError with unique/foreign key/check violations) to AppError variants.
  • Safe, structured logging of internal errors with a generic client-facing message.

Quick Start

Provide a Fromsqlx::Error implementation for your AppError and use fetch_optional when appropriate to avoid RowNotFound in user-facing lookups.

Frequently Asked Questions about sqlx-errors

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I map sqlx database errors to typed AppError responses in Rust?

Map sqlx database errors to typed AppError responses by implementing From<sqlx::Error> for your AppError, converting common variants like RowNotFound and DatabaseError into appropriate HTTP responses.

How do I prevent leaking raw sqlx error strings to web API clients?

Prevent leaking raw sqlx error strings to clients by mapping internal sqlx::Error variants to safe AppError responses, using structured logging for internal details while returning generic client-facing messages.

Does sqlx error handling work across different databases for unique and foreign key violations?

Yes, cross-database error handling uses the DatabaseError trait methods is_unique_violation, is_foreign_key_violation, and is_check_violation to safely classify constraints without relying on database-specific error strings.

What is the best way to handle sqlx RowNotFound errors in user-facing lookups?

Handle sqlx RowNotFound errors in user-facing lookups by using fetch_optional instead of fetch_one, which returns None rather than throwing an error, giving you explicit control over the AppError response.

How do I log sqlx errors safely without exposing internal database details?

Log sqlx errors safely by capturing the internal error details in structured logs while returning a generic AppError message to the client, ensuring database constraint violations are classified without leaking raw strings.

Why should I use typed AppError responses instead of raw sqlx errors in Rust web APIs?

Use typed AppError responses instead of raw sqlx errors to standardize HTTP status codes for specific constraint violations and prevent sensitive database schema details from reaching external API clients.