• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / pg_graphql / 17217734549

25 Aug 2025 06:45PM UTC coverage: 91.359% (-1.9%) from 93.265%
17217734549

push

github

web-flow
Merge pull request #599 from supabase/or/error-types

Refactor Error responses to use a type vs String

245 of 566 new or added lines in 9 files covered. (43.29%)

1 existing line in 1 file now uncovered.

7549 of 8263 relevant lines covered (91.36%)

1135.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/src/error.rs
1
use graphql_parser::query::ParseError as GraphQLParseError;
2
use thiserror::Error;
3

4
/// Central error type for all pg_graphql operations.
5
/// This replaces string-based error handling with strongly-typed variants.
6
#[derive(Debug, Error, Clone)]
7
pub enum GraphQLError {
8
    /// GraphQL query parsing errors
9
    #[error("Parse error: {0}")]
10
    Parse(String),
11

12
    /// Field resolution errors
13
    #[error("Unknown field \"{field}\" on type {type_name}")]
14
    FieldNotFound { field: String, type_name: String },
15

16
    /// General operation errors with context
17
    #[error("{message}")]
18
    Operation { context: String, message: String },
19
}
20

21
impl From<GraphQLParseError> for GraphQLError {
NEW
22
    fn from(err: GraphQLParseError) -> Self {
×
NEW
23
        Self::Parse(err.to_string())
×
NEW
24
    }
×
25
}
26

27
impl From<String> for GraphQLError {
28
    fn from(err: String) -> Self {
2✔
29
        Self::Operation {
2✔
30
            context: "Error".to_string(),
2✔
31
            message: err,
2✔
32
        }
2✔
33
    }
2✔
34
}
35

36
impl From<&str> for GraphQLError {
NEW
37
    fn from(err: &str) -> Self {
×
NEW
38
        Self::Operation {
×
NEW
39
            context: "Error".to_string(),
×
NEW
40
            message: err.to_string(),
×
NEW
41
        }
×
NEW
42
    }
×
43
}
44

45
impl GraphQLError {
46
    /// Creates a field not found error
47
    pub fn field_not_found(field: impl Into<String>, type_name: impl Into<String>) -> Self {
1✔
48
        Self::FieldNotFound {
1✔
49
            field: field.into(),
1✔
50
            type_name: type_name.into(),
1✔
51
        }
1✔
52
    }
1✔
53

54
    /// Creates a validation error
55
    pub fn validation(message: impl Into<String>) -> Self {
37✔
56
        Self::Operation {
37✔
57
            context: "Validation error".to_string(),
37✔
58
            message: message.into(),
37✔
59
        }
37✔
60
    }
37✔
61

62
    /// Creates a schema error
63
    pub fn schema(message: impl Into<String>) -> Self {
2✔
64
        Self::Operation {
2✔
65
            context: "Schema error".to_string(),
2✔
66
            message: message.into(),
2✔
67
        }
2✔
68
    }
2✔
69

70
    /// Creates a type error
71
    pub fn type_error(message: impl Into<String>) -> Self {
56✔
72
        Self::Operation {
56✔
73
            context: "Type error".to_string(),
56✔
74
            message: message.into(),
56✔
75
        }
56✔
76
    }
56✔
77

78
    /// Creates an argument error
NEW
79
    pub fn argument(message: impl Into<String>) -> Self {
×
NEW
80
        Self::Operation {
×
NEW
81
            context: "Argument error".to_string(),
×
NEW
82
            message: message.into(),
×
NEW
83
        }
×
NEW
84
    }
×
85

86
    /// Creates a SQL generation error
87
    pub fn sql_generation(message: impl Into<String>) -> Self {
1✔
88
        Self::Operation {
1✔
89
            context: "SQL generation error".to_string(),
1✔
90
            message: message.into(),
1✔
91
        }
1✔
92
    }
1✔
93

94
    /// Creates a SQL execution error
NEW
95
    pub fn sql_execution(message: impl Into<String>) -> Self {
×
NEW
96
        Self::Operation {
×
NEW
97
            context: "SQL execution error".to_string(),
×
NEW
98
            message: message.into(),
×
NEW
99
        }
×
NEW
100
    }
×
101

102
    /// Creates an internal error
103
    pub fn internal(message: impl Into<String>) -> Self {
663✔
104
        Self::Operation {
663✔
105
            context: "Internal error".to_string(),
663✔
106
            message: message.into(),
663✔
107
        }
663✔
108
    }
663✔
109

110
}
111

112
/// Type alias for Results that use GraphQLError
113
pub type GraphQLResult<T> = Result<T, GraphQLError>;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc