From d2448d8563348f3046d2ef07865c621d81f4ef52 Mon Sep 17 00:00:00 2001 From: "Francois @fanf42 Armand" Date: Wed, 12 Jun 2024 17:04:33 +0200 Subject: [PATCH] Fixes #24996: UpdateHttpDatasetTest datasource test get blocked forever --- .../datasources/UpdateHttpDataset.scala | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/datasources/src/main/scala/com/normation/plugins/datasources/UpdateHttpDataset.scala b/datasources/src/main/scala/com/normation/plugins/datasources/UpdateHttpDataset.scala index 936adf31e..5847f15d1 100644 --- a/datasources/src/main/scala/com/normation/plugins/datasources/UpdateHttpDataset.scala +++ b/datasources/src/main/scala/com/normation/plugins/datasources/UpdateHttpDataset.scala @@ -54,10 +54,8 @@ import com.normation.zio.* import com.softwaremill.quicklens.* import com.typesafe.config.ConfigValue import net.minidev.json.JSONArray -import net.minidev.json.JSONAware import net.minidev.json.JSONStyle import net.minidev.json.JSONValue -import scala.util.control.NonFatal import scalaj.http.Http import scalaj.http.HttpOptions import zio.* @@ -338,18 +336,10 @@ object JsonSelect { } for { - jsonValue <- - IOResult.attemptZIO(try { - json.read[JSONAware](path).succeed - } catch { - case _: ClassCastException => - try { - json.read[Any](path).toString.succeed - } catch { - case NonFatal(ex) => SystemError(s"Error when trying to get path '${path.getPath}': ${ex.getMessage}", ex).fail - } - case NonFatal(ex) => SystemError(s"Error when trying to get path '${path.getPath}': ${ex.getMessage}", ex).fail - }) + jsonValue <- ZIO + .attempt(json.read[JSONArray](path)) + .catchSome { case _: ClassCastException => ZIO.attempt(json.read[Any](path)) } + .mapError(ex => SystemError(s"Error when trying to get path '${path.getPath}': ${ex.getMessage}", ex)) // we want to special process the case where the list has only one value to let the // user access them directly WITHOUT having to lift it from the array. // The case with no data is considered to be "".