Merge pull request 'Change sbot::init to not panic and instead return an error' (#51) from no-panic into main

Reviewed-on: #51
This commit is contained in:
notplants 2022-07-16 05:57:36 +00:00
commit 3c37297018
3 changed files with 24 additions and 14 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "golgi"
version = "0.2.2"
version = "0.2.3"
edition = "2021"
authors = ["Max Fowler <max@mfowler.info>", "Andrew Reid <glyph@mycelial.technology>"]
readme = "README.md"

View File

@ -77,7 +77,7 @@ impl std::fmt::Display for GolgiError {
// TODO: improve this variant with a context message
// then have the core display msg be: "SSB RPC error: {}", context
GolgiError::Rpc(ref err) => write!(f, "SSB RPC failure: {}", err),
GolgiError::Sbot(ref err) => write!(f, "Sbot returned an error response: {}", err),
GolgiError::Sbot(ref err) => write!(f, "Sbot encountered an error: {}", err),
GolgiError::SigilLink(ref context) => write!(f, "SSB blob ID error: {}", context),
GolgiError::SerdeJson(_) => write!(f, "Failed to serialize JSON slice"),
//GolgiError::WhoAmI(ref err) => write!(f, "{}", err),

View File

@ -75,25 +75,35 @@ impl Sbot {
};
let OwnedIdentity { pk, sk, id } = match keystore {
Keystore::Patchwork => keystore::from_patchwork_local()
.await
.expect("couldn't read local patchwork secret from default location"),
Keystore::GoSbot => keystore::from_gosbot_local()
.await
.expect("couldn't read local go-sbot secret from default location"),
Keystore::Patchwork => keystore::from_patchwork_local().await.map_err(|_err| {
GolgiError::Sbot(
"sbot initialization error: couldn't read local patchwork secret from default location".to_string(),
)
})?,
Keystore::GoSbot => keystore::from_gosbot_local().await.map_err(|_err| {
GolgiError::Sbot(
"sbot initialization error: couldn't read local go-sbot secret from default location".to_string(),
)
})?,
Keystore::CustomGoSbot(key_path) => {
keystore::from_custom_gosbot_keypath(key_path.to_string())
.await
.unwrap_or_else(|_| {
panic!("couldn't read local go-sbot secret from: {}", key_path)
})
.map_err(|_err| {
GolgiError::Sbot(format!(
"sbot initialization error: couldn't read local go-sbot secret from: {}",
key_path
))
})?
}
Keystore::CustomPatchwork(key_path) => {
keystore::from_custom_patchwork_keypath(key_path.to_string())
.await
.unwrap_or_else(|_| {
panic!("couldn't read local patchwork secret from: {}", key_path)
})
.map_err(|_err| {
GolgiError::Sbot(format!(
"sbot initialization error: couldn't read local patchwork secret from: {}",
key_path
))
})?
}
};