diff options
Diffstat (limited to 'crates/turtle/src/atuin_server/database/mod.rs')
| -rw-r--r-- | crates/turtle/src/atuin_server/database/mod.rs | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/crates/turtle/src/atuin_server/database/mod.rs b/crates/turtle/src/atuin_server/database/mod.rs index bb64767a..43fe5c3b 100644 --- a/crates/turtle/src/atuin_server/database/mod.rs +++ b/crates/turtle/src/atuin_server/database/mod.rs @@ -14,29 +14,29 @@ pub(crate) enum DbError { impl Display for DbError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - DbError::NotFound => write!(f, "Not found"), - DbError::Other(report) => write!(f, "Other: {report}"), + Self::NotFound => write!(f, "Not found"), + Self::Other(report) => write!(f, "Other: {report}"), } } } impl From<time::error::ComponentRange> for DbError { fn from(error: time::error::ComponentRange) -> Self { - DbError::Other(error.into()) + Self::Other(error.into()) } } impl From<time::error::Error> for DbError { fn from(error: time::error::Error) -> Self { - DbError::Other(error.into()) + Self::Other(error.into()) } } impl From<sqlx::Error> for DbError { fn from(error: sqlx::Error) -> Self { match error { - sqlx::Error::RowNotFound => DbError::NotFound, - error => DbError::Other(error.into()), + sqlx::Error::RowNotFound => Self::NotFound, + error => Self::Other(error.into()), } } } @@ -54,6 +54,7 @@ pub(crate) enum DbType { #[derive(Clone, Deserialize, Serialize)] pub(crate) struct DbSettings { pub(crate) db_uri: String, + /// Optional URI for read replicas. If set, read-only queries will use this connection. pub(crate) read_db_uri: Option<String>, } @@ -69,12 +70,13 @@ impl DbSettings { } fn redact_db_uri(uri: &str) -> String { - url::Url::parse(uri) - .map(|mut url| { - let _ = url.set_password(Some("****")); + url::Url::parse(uri).map_or_else( + |_| uri.to_string(), + |mut url| { + url.set_password(Some("****")).expect("should be possible"); url.to_string() - }) - .unwrap_or_else(|_| uri.to_string()) + }, + ) } // Do our best to redact passwords so they're not logged in the event of an error. |
