Skip to content

Commit

Permalink
resctl-bench: lambda: return Github-related errors as responses
Browse files Browse the repository at this point in the history
Provide error messages both for lambda logs and for the client instead
of panicking and showing a stack trace.

Signed-off-by: Ricardo Cañuelo <[email protected]>
  • Loading branch information
Ricardo Cañuelo committed Oct 29, 2024
1 parent 0a793d8 commit a861c55
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions resctl-bench/src/lambda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,18 @@ pub async fn run() -> Result<()> {
&sysinfo,
&format!("{}\n\n{}```\n{}\n```", s3_url, identification, summary),
)
.await?;
.await;
if let Err(e) = issue_url {
error!("Error creating Github issue: {:#}", e);
return Ok(Response {
issue: None,
error_type: Some(format!("Custom")),
error_message: Some(format!("Error creating Github issue: {}", e)),
});
}

Ok::<_, Error>(Response {
issue: Some(issue_url),
issue: Some(issue_url.unwrap()),
error_type: None,
error_message: None,
})
Expand Down Expand Up @@ -176,27 +184,28 @@ impl LambdaHelper {
.set_name(Some("/iocost-bot/appid".to_string()))
.send()
.await
.expect("Failed to query parameter")
.context("Failed to query AWS parameter /iocost-bot/appid")?
.parameter
.expect("Could not find parameter")
.context("Could not find AWS parameter /iocost-bot/appid")?
.value
.expect("Parameter value is None");
.context("Value of parameter AWS /iocost-bot/appid is None")?;

let pem = self
.ssm
.get_parameter()
.set_name(Some("/iocost-bot/privatekey".to_string()))
.send()
.await
.expect("Failed to query parameter")
.context("Failed to query parameter AWS /iocost-bot/privatekey")?
.parameter
.expect("Could not find parameter")
.context("Could not find parameter AWS /iocost-bot/privatekey")?
.value
.expect("Parameter value is None");
.context("Value of parameter AWS /iocost-bot/privatekey is None")?;

let token = octocrab::auth::create_jwt(
app_id.parse::<u64>().unwrap().into(),
&jsonwebtoken::EncodingKey::from_rsa_pem(pem.as_bytes()).unwrap(),
&jsonwebtoken::EncodingKey::from_rsa_pem(pem.as_bytes())
.context("Couldn't create a JWT for Github authentication")?,
)
.unwrap();

Expand Down

0 comments on commit a861c55

Please sign in to comment.