Error Handling

Prax provides comprehensive error types with unique error codes, actionable suggestions, and helpful context to quickly diagnose and fix issues.

Basic Error Handling

Use pattern matching or boolean checks to handle different error types.

Error Codes

Every error has a unique code in the Pxxxx format for easy identification and documentation lookup.

Error Code Categories

Range Category Description
P1xxx Query Record not found, invalid filters
P2xxx Constraint Unique, foreign key, not null violations
P3xxx Connection Connection failures, pool exhausted, auth
P4xxx Transaction Deadlocks, serialization failures
P5xxx Execution Timeouts, syntax errors
P6xxx Data Type mismatches, serialization
P7xxx Configuration Invalid config, missing settings
P9xxx Internal Internal errors, bugs

Actionable Error Messages

Errors include suggestions for how to fix the issue, with code examples when applicable.

Colored Terminal Output

Use display_colored() for beautiful terminal output with ANSI colors.

Adding Context

Enrich errors with additional context for better debugging.

Error Macro

Create custom errors quickly with the query_error! macro.

Error Checks

Use boolean methods to check error categories without pattern matching.

✓ Retryable Errors

The is_retryable() check identifies transient errors that are safe to retry: connection timeouts, pool exhaustion, deadlocks, and serialization failures. Use this with the RetryMiddleware for automatic handling.