<commit_before>package helpers

import play.api.libs.json.{Json, Reads}
import org.scalatest.Assertions.fail

object JsonUtils {

  def deserializeJsonToModel[A](json: String)(implicit fjs: Reads[A]): A = {
    val parsedJsValue = Json.parse(json)
    val fromJson = Json.fromJson[A](parsedJsValue)
    fromJson.asEither match {
      case Left(errors) =>
        fail(s"Failed to deserialize this json: $json into a model")
      case Right(model) =>
        model
    }
  }

}<commit_msg>Refactor: add model name to failure message<commit_after>package helpers

import models.domain.common.CacheKey
import org.scalatest.Assertions.fail
import play.api.libs.json.{Json, Reads}

object JsonUtils {

  def deserializeJsonToModel[A](json: String)(implicit fjs: Reads[A], cacheKey: CacheKey[A]): A = {
    val parsedJsValue = Json.parse(json)
    val fromJson = Json.fromJson[A](parsedJsValue)
    fromJson.asEither match {
      case Left(errors) =>
        fail(s"Failed to deserialize this json: $json into a model of type ${cacheKey.value}")
      case Right(model) =>
        model
    }
  }

}
{'fraction_non_alphanumeric': 0.11313868613138686, 'fraction_numerical': 0.0, 'mean_word_length': 3.6483050847457625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '898798', 'n_tokens_mistral': 362, 'n_tokens_neox': 355, 'n_words': 87}