Skip to main content

uqa_client/
sql_diagnostic_category.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7use serde::{Deserialize, Serialize};
8
9/// Closed SQL failure categories; never derived from an error message.
10#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
11#[serde(rename_all = "snake_case")]
12pub enum SQLDiagnosticCategory {
13    Syntax,
14    UndefinedTable,
15    UndefinedColumn,
16    AmbiguousColumn,
17    UndefinedFunction,
18    AmbiguousFunction,
19    TypeMismatch,
20    InvalidParameter,
21    VectorDimensionMismatch,
22    IndexRequired,
23    UndefinedObject,
24    DuplicateObject,
25    ConstraintViolation,
26    Unsupported,
27    Cancelled,
28    ResourceExhausted,
29    Transaction,
30    Permission,
31    Internal,
32    Other,
33}
34
35impl SQLDiagnosticCategory {
36    pub const fn as_str(self) -> &'static str {
37        match self {
38            Self::Syntax => "syntax",
39            Self::UndefinedTable => "undefined_table",
40            Self::UndefinedColumn => "undefined_column",
41            Self::AmbiguousColumn => "ambiguous_column",
42            Self::UndefinedFunction => "undefined_function",
43            Self::AmbiguousFunction => "ambiguous_function",
44            Self::TypeMismatch => "type_mismatch",
45            Self::InvalidParameter => "invalid_parameter",
46            Self::VectorDimensionMismatch => "vector_dimension_mismatch",
47            Self::IndexRequired => "index_required",
48            Self::UndefinedObject => "undefined_object",
49            Self::DuplicateObject => "duplicate_object",
50            Self::ConstraintViolation => "constraint_violation",
51            Self::Unsupported => "unsupported",
52            Self::Cancelled => "cancelled",
53            Self::ResourceExhausted => "resource_exhausted",
54            Self::Transaction => "transaction",
55            Self::Permission => "permission",
56            Self::Internal => "internal",
57            Self::Other => "other",
58        }
59    }
60
61    /// Source-owned guidance, independent of remote or customer-controlled text.
62    pub const fn hint(self) -> Option<&'static str> {
63        match self {
64            Self::Syntax => Some("Check SQL syntax at the reported character position."),
65            Self::UndefinedTable => Some("Check the relation name and schema search path."),
66            Self::UndefinedColumn => Some("Check column names against the relation schema."),
67            Self::AmbiguousColumn => Some("Qualify the column with its relation alias."),
68            Self::UndefinedFunction | Self::AmbiguousFunction | Self::TypeMismatch => {
69                Some("Check argument types and explicit casts.")
70            }
71            Self::VectorDimensionMismatch => {
72                Some("Match the vector dimensions to the declared type.")
73            }
74            Self::IndexRequired => Some("Create a GIN text index on the searched field."),
75            _ => None,
76        }
77    }
78}