pgwire/
error.rs

1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::io::Error as IoError;
16
17use thiserror::Error;
18
19use crate::pg_server::BoxedError;
20pub type PsqlResult<T> = std::result::Result<T, PsqlError>;
21
22/// Error type used in pgwire crates.
23#[derive(Error, Debug)]
24pub enum PsqlError {
25    #[error("Failed to start a new session: {0}")]
26    StartupError(
27        #[source]
28        #[backtrace]
29        BoxedError,
30    ),
31
32    #[error("Invalid password")]
33    PasswordError,
34
35    #[error("Failed to run the query: {0}")]
36    SimpleQueryError(
37        #[source]
38        #[backtrace]
39        BoxedError,
40    ),
41
42    #[error("Failed to prepare the statement: {0}")]
43    ExtendedPrepareError(
44        #[source]
45        #[backtrace]
46        BoxedError,
47    ),
48
49    #[error("Failed to execute the statement: {0}")]
50    ExtendedExecuteError(
51        #[source]
52        #[backtrace]
53        BoxedError,
54    ),
55
56    #[error(transparent)]
57    IoError(#[from] IoError),
58
59    /// Uncategorized error for describe, bind.
60    #[error(transparent)]
61    Uncategorized(
62        #[from]
63        #[backtrace]
64        BoxedError,
65    ),
66
67    #[error("Panicked when handling the request: {0}
68This is a bug. We would appreciate a bug report at:
69  https://github.com/risingwavelabs/risingwave/issues/new?labels=type%2Fbug&template=bug_report.yml")]
70    Panic(String),
71
72    #[error("Unable to setup an SSL connection")]
73    SslError(#[from] openssl::ssl::Error),
74
75    #[error("terminating connection due to idle-in-transaction timeout")]
76    IdleInTxnTimeout,
77
78    #[error("Server throttled: {0}")]
79    ServerThrottle(String),
80}
81
82impl PsqlError {
83    pub fn no_statement() -> Self {
84        PsqlError::Uncategorized("No statement found".into())
85    }
86
87    pub fn no_portal() -> Self {
88        PsqlError::Uncategorized("No portal found".into())
89    }
90}