Skip to content

Commit

Permalink
Merge pull request #1192 from guardian/add-more-logging-to-iam-creden…
Browse files Browse the repository at this point in the history
…tials-report-code

Improve error logging on IAM credentials report
  • Loading branch information
adamnfish authored Jan 21, 2025
2 parents 0cde035 + f2c5dfc commit 15c9da5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion hq/app/aws/AwsAsyncHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object AwsAsyncHandler {
} else if (e.getMessage.contains("Rate exceeded")) {
Failure.rateLimitExceeded(serviceNameOpt, awsClient).attempt
} else {
Failure.awsError(serviceNameOpt, awsClient).attempt
Failure.awsError(serviceNameOpt, awsClient, e).attempt
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion hq/app/logic/IamUnrecognisedUsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ object IamUnrecognisedUsers extends Logging {
def getCredsReportDisplayForAccount[A, B](allCreds: Map[A, Either[FailedAttempt, B]]): List[(A, B)] = {
allCreds.toList.foldLeft[List[(A, B)]](Nil) {
case (acc, (_, Left(failure))) =>
logger.error(s"unable to generate credential report display: ${failure.logMessage}")
failure.firstException match {
case Some(cause) =>
logger.error(s"unable to generate credential report display: ${failure.logMessage}", cause)
case None =>
logger.error(s"unable to generate credential report display: ${failure.logMessage}")
}
acc
case (acc, (account, Right(credReportDisplay))) =>
(account, credReportDisplay) :: acc
Expand Down
4 changes: 2 additions & 2 deletions hq/app/utils/attempt/Failure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ case class Failure(
object Failure {
// Pre-defined "common" failures

def awsError(serviceNameOpt: Option[String], clientContext: AwsClient[_]): Failure = {
def awsError(serviceNameOpt: Option[String], clientContext: AwsClient[_], err: Throwable): Failure = {
val context = contextString(clientContext)
val details = serviceNameOpt.fold(s"AWS unknown error, unknown service (check logs for stacktrace), $context") { serviceName =>
s"AWS unknown error, service: $serviceName (check logs for stacktrace), $context"
}
val friendlyMessage = serviceNameOpt.fold("Unknown error while making API calls to AWS.") { serviceName =>
s"Unknown error while making an API call to AWS' $serviceName service"
}
Failure(details, friendlyMessage, 500)
Failure(details, friendlyMessage, 500, throwable = Some(err))
}

def notYetLoaded(accountId: String, cacheContent: String): Failure = {
Expand Down

0 comments on commit 15c9da5

Please sign in to comment.