Skip to content

Commit

Permalink
Common: fix NullPointerException on serialilzing invalid state (close #…
Browse files Browse the repository at this point in the history
  • Loading branch information
chuwy committed Oct 11, 2020
1 parent 469fab1 commit 437a69c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ final case class ApiRequestEnrichment[F[_]: Monad: HttpClient](
contexts = jsons.parTraverse { json =>
SelfDescribingData
.parse(json)
.leftMap(e => NonEmptyList.one(s"${json.noSpaces} is not self-describing, ${e.code}"))
.leftMap(e => NonEmptyList.one(s"${json.noSpaces} is not self-describing JSON, ${e.code}"))
}
outputs <- EitherT.fromEither[F](contexts)
} yield outputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
package com.snowplowanalytics.snowplow.enrich.common.enrichments.registry.apirequest

final case class ValueNotFoundException(message: String) extends Throwable {
override def getMessage: String = "API Request enrichment:" ++ toString
override def toString = s"Value not found $message"
}

final case class JsonPathException(message: String) extends Throwable {
override def getMessage: String = "API Request enrichment:" ++ toString
override def toString = s"JSONPath error $message"
}

final case class InvalidStateException(message: String) extends Throwable {
override def getMessage: String = "API Request enrichment:" ++ toString
override def toString = message
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ final case class Output(schema: String, json: Option[JsonOutput]) {
def parseResponse(apiResponse: String): Either[Throwable, Json] =
json match {
case Some(jsonOutput) => jsonOutput.parseResponse(apiResponse)
case output =>
new InvalidStateException(s"Error: Unknown output [$output]").asLeft // Cannot happen now
case None =>
new InvalidStateException(s"Error: output key is missing").asLeft // Cannot happen now
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package com.snowplowanalytics.snowplow.enrich.common.enrichments.registry.sqlque
sealed trait SqlQueryEnrichmentError extends Throwable {
val message: String
override def toString = message
override def getMessage = message
override def getMessage = "SQL Query enrichment: " ++ message
}
final case class ValueNotFoundException(message: String) extends SqlQueryEnrichmentError
final case class JsonPathException(message: String) extends SqlQueryEnrichmentError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ object SqlQueryEnrichment extends ParseableEnrichment {
* @param db source DB configuration
* @param query string representation of prepared SQL statement
* @param output configuration of output context
* @param ttl cache TTL
* @param ttl cache TTL in milliseconds
* @param cache actual mutable LRU cache
* @param connection initialized DB connection (a mutable single-value cache)
*/
Expand Down

0 comments on commit 437a69c

Please sign in to comment.