'Understanding IO and .mapError in SCALA

Can anyone pls expain the IO.effect(a) .mapError(SecretsError.exception) in the below effect method. Thanks

import org.json.JSONObject
import zio.IO

object Secrets {
  sealed trait SecretsError
  object SecretsError {
    final case class ExceptionEncountered(message: String) extends SecretsError

    def exception(e: Throwable): SecretsError =
      ExceptionEncountered(s"Exception: ${Apps.stackTrace(e)}")
  }


private def effect[A](a: => A): IO[SecretsError, A] =
    IO.effect(a)
      .mapError(SecretsError.exception)```



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source