Skip to content

Commit 5385a67

Browse files
authored
Merge pull request #174 from cipherstash/error-message-internal-error
feat: improve error message for internal errors
2 parents d1f2d0f + 22de704 commit 5385a67

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

docs/errors.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- [Invalid parameter](#mapping-invalid-parameter)
1313
- [Invalid SQL statement](#mapping-invalid-sql-statement)
1414
- [Unsupported parameter type](#mapping-unsupported-parameter-type)
15+
- [Internal Error](#mapping-internal-error)
1516

1617
- Encrypt Errors:
1718
- [Column could not be encrypted](#encrypt-column-could-not-be-encrypted)
@@ -164,6 +165,28 @@ Check the supported types for encrypted columns.
164165

165166

166167

168+
<!-- ---------------------------------------------------------------------------------------------------- -->
169+
170+
171+
## Internal Mapper error <a id='mapping-internal-error'></a>
172+
173+
An internal error occurred when attempting to rewrite the SQL statement.
174+
This could be due to an internal invariant failure or because of a specific fragment of unsupported SQL syntax.
175+
176+
### Error message
177+
178+
```
179+
Statement encountered an internal error. This may be a bug in the statement mapping module of CipherStash Proxy.
180+
```
181+
182+
### How to Fix
183+
184+
If you are running an older version of CipherStash Proxy, please update to the latest version.
185+
186+
If the error persists, please contact CipherStash [support](https://cipherstash.com/support).
187+
188+
189+
167190
<!-- ---------------------------------------------------------------------------------------------------- -->
168191

169192

packages/cipherstash-proxy-integration/src/extended_protocol_error_messages.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ mod tests {
6666
if let Err(err) = result {
6767
let msg = err.to_string();
6868

69-
assert_eq!(msg, "db error: ERROR: Column 'encrypted_unconfigured' in table 'unconfigured' has no Encrypt configuration. For help visit https://github.com/cipherstash/proxy/docs/errors.md#encrypt-unknown-column");
69+
assert_eq!(msg, "db error: ERROR: Column 'encrypted_unconfigured' in table 'unconfigured' has no Encrypt configuration. For help visit https://github.com/cipherstash/proxy/blob/main/docs/errors.md#encrypt-unknown-column");
7070
} else {
7171
unreachable!();
7272
}
@@ -122,7 +122,7 @@ mod tests {
122122
if let Err(err) = result {
123123
let msg = err.to_string();
124124
info!("{}", msg);
125-
assert_eq!(msg, "db error: ERROR: sql parser error: Expected: SELECT, VALUES, or a subquery in the query body, found: id at Line: 1, Column: 23. For help visit https://github.com/cipherstash/proxy/docs/errors.md#mapping-invalid-sql-statement");
125+
assert_eq!(msg, "db error: ERROR: sql parser error: Expected: SELECT, VALUES, or a subquery in the query body, found: id at Line: 1, Column: 23. For help visit https://github.com/cipherstash/proxy/blob/main/docs/errors.md#mapping-invalid-sql-statement");
126126
} else {
127127
unreachable!();
128128
}

packages/cipherstash-proxy/src/error.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::io;
66
use thiserror::Error;
77
use tokio::time::error::Elapsed;
88

9-
const ERROR_DOC_BASE_URL: &str = "https://github.com/cipherstash/proxy/docs/errors.md";
9+
const ERROR_DOC_BASE_URL: &str = "https://github.com/cipherstash/proxy/blob/main/docs/errors.md";
1010

1111
#[derive(Error, Debug)]
1212
pub enum Error {
@@ -89,6 +89,9 @@ pub enum MappingError {
8989

9090
#[error("Could not parse parameter")]
9191
CouldNotParseParameter,
92+
93+
#[error("Statement encountered an internal error. This may be a bug in the statement mapping module of CipherStash Proxy. Please visit {}#mapping-internal-error for more information.", ERROR_DOC_BASE_URL)]
94+
Internal(String),
9295
}
9396

9497
#[derive(Error, Debug)]
@@ -304,3 +307,16 @@ impl From<chrono::ParseError> for Error {
304307
MappingError::CouldNotParseParameter.into()
305308
}
306309
}
310+
311+
#[cfg(test)]
312+
mod tests {
313+
use super::*;
314+
315+
#[test]
316+
fn test_internal_error_message() {
317+
let error = MappingError::Internal("unexpected bug encounterd".to_string());
318+
let message = error.to_string();
319+
320+
assert_eq!(format!("Statement encountered an internal error. This may be a bug in the statement mapping module of CipherStash Proxy. Please visit {}#mapping-internal-error for more information.", ERROR_DOC_BASE_URL), message);
321+
}
322+
}

packages/cipherstash-proxy/src/postgresql/frontend.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::prometheus::{
2525
use crate::Encrypted;
2626
use bytes::BytesMut;
2727
use cipherstash_client::encryption::Plaintext;
28-
use eql_mapper::{self, EqlValue, NodeKey, TableColumn, TypedStatement};
28+
use eql_mapper::{self, EqlMapperError, EqlValue, NodeKey, TableColumn, TypedStatement};
2929
use metrics::{counter, histogram};
3030
use pg_escape::quote_literal;
3131
use serde::Serialize;
@@ -737,6 +737,16 @@ where
737737

738738
Ok(typed_statement)
739739
}
740+
Err(EqlMapperError::InternalError(str)) => {
741+
warn!(
742+
client_id = self.context.client_id,
743+
msg = "Internal Error in EQL Mapper",
744+
mapping_errors_enabled = self.encrypt.config.mapping_errors_enabled(),
745+
error = str,
746+
);
747+
counter!(STATEMENTS_UNMAPPABLE_TOTAL).increment(1);
748+
Err(MappingError::Internal(str).into())
749+
}
740750
Err(err) => {
741751
warn!(
742752
client_id = self.context.client_id,

0 commit comments

Comments
 (0)