Skip to content

Commit

Permalink
Print stack trace on --verbose and failure
Browse files Browse the repository at this point in the history
  • Loading branch information
laurilehmijoki committed Jun 28, 2014
1 parent 60b3cf8 commit 5f7827b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 19 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

This project uses [Semantic Versioning](http://semver.org).

## 2.1.13

* Print JVM stack trace on error and `--verbose`

This eases debugging

## 2.1.12

* Exit with status 1 when encountering an unrecognised CLI option
Expand Down
2 changes: 1 addition & 1 deletion lib/s3_website/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module S3Website
VERSION = '2.1.12'
VERSION = '2.1.13'
end
5 changes: 3 additions & 2 deletions src/main/scala/s3/website/CloudFront.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package s3.website

import s3.website.ErrorReport._
import s3.website.model.{FileUpdate, Config}
import com.amazonaws.services.cloudfront.{AmazonCloudFrontClient, AmazonCloudFront}
import com.amazonaws.services.cloudfront.model.{TooManyInvalidationsInProgressException, Paths, InvalidationBatch, CreateInvalidationRequest}
Expand Down Expand Up @@ -60,8 +61,8 @@ object CloudFront {
def reportMessage = s"${Invalidated.renderVerb} ${invalidatedItemsCount ofType "item"} on CloudFront"
}

case class FailedInvalidation(error: Throwable) extends FailureReport {
def reportMessage = s"Failed to invalidate the CloudFront distribution (${error.getMessage})"
case class FailedInvalidation(error: Throwable)(implicit logger: Logger) extends ErrorReport {
def reportMessage = errorMessage(s"Failed to invalidate the CloudFront distribution", error)
}

def awsCloudFrontClient(config: Config) = new AmazonCloudFrontClient(awsCredentials(config))
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/s3/website/Logger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Logger(val verboseOutput: Boolean) {
def fail(msg: String) = log(Failure, msg)

def info(report: SuccessReport) = log(Success, report.reportMessage)
def info(report: FailureReport) = fail(report.reportMessage)
def info(report: ErrorReport) = fail(report.reportMessage)

def pending(msg: String) = log(Wait, msg)

Expand Down
11 changes: 6 additions & 5 deletions src/main/scala/s3/website/S3.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package s3.website

import s3.website.ErrorReport.errorMessage
import s3.website.model._
import com.amazonaws.services.s3.{AmazonS3, AmazonS3Client}
import com.amazonaws.services.s3.model._
Expand Down Expand Up @@ -140,7 +141,7 @@ object S3 {
type UpdateFutures = Seq[Either[ErrorReport, Future[PushErrorOrSuccess]]]
type ErrorOrS3Files = Either[ErrorReport, Seq[S3File]]

sealed trait PushFailureReport extends FailureReport
sealed trait PushFailureReport extends ErrorReport
sealed trait PushSuccessReport extends SuccessReport {
def s3Key: String
}
Expand Down Expand Up @@ -208,12 +209,12 @@ object S3 {
def reportMessage = s"${Deleted.renderVerb} $s3Key"
}

case class FailedUpload(s3Key: String, error: Throwable) extends PushFailureReport {
def reportMessage = s"Failed to upload $s3Key (${error.getMessage})"
case class FailedUpload(s3Key: String, error: Throwable)(implicit logger: Logger) extends PushFailureReport {
def reportMessage = errorMessage(s"Failed to upload $s3Key", error)
}

case class FailedDelete(s3Key: String, error: Throwable) extends PushFailureReport {
def reportMessage = s"Failed to delete $s3Key (${error.getMessage})"
case class FailedDelete(s3Key: String, error: Throwable)(implicit logger: Logger) extends PushFailureReport {
def reportMessage = errorMessage(s"Failed to delete $s3Key", error)
}

type S3ClientProvider = (Config) => AmazonS3
Expand Down
22 changes: 12 additions & 10 deletions src/main/scala/s3/website/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,27 @@ package object website {
}
trait SuccessReport extends Report

trait FailureReport extends Report

trait ErrorReport extends Report

object ErrorReport {
def apply(t: Throwable)(implicit logger: Logger) = new ErrorReport {
override def reportMessage = {
val extendedReport =
if (logger.verboseOutput)
Some(t.getStackTrace take 5)
else
None
s"${t.getMessage}${extendedReport.fold("")(stackTraceElems => "\n" + stackTraceElems.mkString("\n"))}"
}
override def reportMessage = errorMessage(t)
}

def apply(msg: String) = new ErrorReport {
override def reportMessage = msg
}

def errorMessage(msg: String, t: Throwable)(implicit logger: Logger): String = s"$msg (${errorMessage(t)})"

def errorMessage(t: Throwable)(implicit logger: Logger): String = {
val extendedReport =
if (logger.verboseOutput)
Some(t.getStackTrace)
else
None
s"${t.getMessage}${extendedReport.fold("")(stackTraceElems => "\n" + stackTraceElems.mkString("\n"))}"
}
}

trait RetrySetting {
Expand Down

0 comments on commit 5f7827b

Please sign in to comment.