supabase_rust_client/
error.rs

1// src/error.rs
2
3// Define custom error types for the Supabase client operations.
4// Use libraries like thiserror for easier error definition.
5
6use thiserror::Error;
7
8// Use correct error path from supabase-rust-auth v0.2.0
9use supabase_rust_auth::AuthError;
10use supabase_rust_postgrest::PostgrestError;
11
12/// Universal error type for the Supabase client library operations.
13/// This now mostly wraps or maps errors from the `supabase_rust_gftd` crate.
14#[derive(Error, Debug)]
15pub enum SupabaseError {
16    #[error("Configuration error: Missing or invalid {0}")]
17    Config(String), // e.g., "SUPABASE_URL"
18
19    #[error("Initialization failed: {0}")]
20    Initialization(String), // For general client setup issues
21
22    // Revert to original error wrapping
23    #[error("Authentication error: {0}")]
24    Auth(#[from] AuthError),
25
26    #[error("Database error: {0}")]
27    Postgrest(#[from] PostgrestError),
28
29    #[error("Realtime error: {0}")]
30    Realtime(String), // Keep as String for now as realtime code is commented out
31
32    #[error("Storage error: {0}")]
33    Storage(String), // Keep as String
34
35    #[error("Function error: {0}")]
36    Function(String), // Keep as String
37
38    // Keep utility errors
39    #[error("Network request error: {0}")]
40    Network(#[from] reqwest::Error),
41
42    #[error("URL parsing error: {0}")]
43    UrlParse(#[from] url::ParseError),
44
45    #[error("JSON serialization/deserialization error: {0}")]
46    Json(#[from] serde_json::Error),
47
48    #[error("Invalid input: {0}")]
49    InvalidInput(String),
50
51    #[error("Operation timed out")]
52    Timeout,
53
54    #[error("An unexpected error occurred: {0}")]
55    Internal(String),
56
57    #[error("Unknown error")]
58    Unknown,
59}
60
61// Optional: Type aliases for convenience if needed elsewhere
62pub type Result<T> = std::result::Result<T, SupabaseError>;
63
64// Define specific AuthError, DbError etc. as needed, potentially wrapping SupabaseError
65// or being distinct enums.