Skip to content

Commit 5bb6f8c

Browse files
add Json parsing error logging (#153)
1 parent c6d7c1b commit 5bb6f8c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/main/scala/com/codacy/plugins/utils/DockerHelper.scala

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ package com.codacy.plugins.utils
33
import com.codacy.plugins.api.PatternDescription
44
import com.codacy.plugins.api.results.{Pattern, Tool}
55
import com.codacy.plugins.runners.IDocker
6-
import play.api.libs.json.{Format, Json}
6+
import play.api.libs.json.{Format, JsResultException, Json}
7+
import wvlet.log.LogSupport
78

89
import java.io.File
910
import java.nio.file.{Path, Paths}
1011
import scala.util.Try
1112

12-
trait IDockerHelper {
13+
trait IDockerHelper extends LogSupport {
1314
def loadDescription(docker: IDocker): Option[Set[PatternDescription]]
1415
def loadPatterns(docker: IDocker): Option[Tool.Specification]
1516
def loadVersion(docker: IDocker): Option[String]
@@ -68,7 +69,14 @@ abstract class DockerHelper extends IDockerHelper {
6869

6970
private def readJsonDoc[T](docker: IDocker, path: Path)(implicit docFmt: Format[T]): Option[T] = {
7071
val json = readRaw(docker, path).map(Json.parse)
71-
json.flatMap(_.asOpt[T])
72+
json.flatMap(jsValue => {
73+
Try(jsValue.as[T])
74+
.recover({
75+
case e: JsResultException =>
76+
e.errors.foreach(m => error(s"Error parsing JSON: $m"))
77+
throw e
78+
})
79+
.toOption
80+
})
7281
}
73-
7482
}

0 commit comments

Comments
 (0)