Skip to content

Commit

Permalink
fix: helpful error when a secret is not found (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
brokad authored Sep 9, 2022
1 parent 94c0878 commit 757ef4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions service/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub enum Error {
Io(#[from] std::io::Error),
#[error("Database error: {0}")]
Database(String),
#[error("Secret error: {0}")]
Secret(String),
#[error("Panic occurred in shuttle_service::main`: {0}")]
BuildPanic(String),
#[error("Panic occurred in `Service::bind`: {0}")]
Expand Down
13 changes: 10 additions & 3 deletions service/src/secrets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,19 @@ where
self.execute(sqlx::query(Self::CREATE_TABLE_QUERY)).await?;

let key = check_and_lower_secret_key(key)?;
let query = sqlx::query(Self::GET_QUERY).bind(key);
let query = sqlx::query(Self::GET_QUERY).bind(&key);

self.fetch_one(query)
self.fetch_optional(query)
.await
.map(|row| row.get(0))
.map_err(Error::from)
.and_then(|m_one| {
m_one.ok_or_else(|| {
Error::Secret(format!(
"Secret `{key}` not found in service environment. If you have made changes to your `Secrets.toml` file recently, try deploying again to make sure changes are applied correctly."
))
})
})
.map(|one| one.get(0))
}

/// Create (or overwrite if already present) a key/value secret in the database. Will error if
Expand Down

0 comments on commit 757ef4d

Please sign in to comment.