SchemaError

zio.blocks.schema.SchemaError
See theSchemaError companion class
object SchemaError

Constructors of SchemaError values and the kinds of failure they hold.

The constructors that take a trace expect its path nodes from the innermost to the outermost, the order in which a decoder collects them. Pass Nil for the root, and add the path with atField and the other at* methods of the error.

Attributes

Companion
class
Source
SchemaError.scala
Graph
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type

Members list

Type members

Classlikes

case class ConversionFailed(source: DynamicOptic, details: String, cause: Option[SchemaError] = ...) extends IntoError

A conversion or validation failed with the message details, optionally caused by the failures in cause.

A conversion or validation failed with the message details, optionally caused by the failures in cause.

Its message adds at: and the path when the path is not the root. When cause is set, the message lists the messages of cause under Caused by: instead, without the path.

Attributes

Source
SchemaError.scala
Supertypes
trait Serializable
trait Product
trait Equals
trait IntoError
trait Single
class Object
trait Matchable
class Any
Show all
case class DuplicatedField(source: DynamicOptic, fieldName: String) extends Single

The field fieldName appears more than once in the record at source.

The field fieldName appears more than once in the record at source.

Attributes

Source
SchemaError.scala
Supertypes
trait Serializable
trait Product
trait Equals
trait Single
class Object
trait Matchable
class Any
Show all
case class ExpectationMismatch(source: DynamicOptic, expectation: String) extends Single

The value at source has the wrong shape; expectation says what was expected, as in Expected a record.

The value at source has the wrong shape; expectation says what was expected, as in Expected a record.

Attributes

Source
SchemaError.scala
Supertypes
trait Serializable
trait Product
trait Equals
trait Single
class Object
trait Matchable
class Any
Show all
sealed trait IntoError extends Single

The failures of conversions such as Into. ConversionFailed is the only one.

The failures of conversions such as Into. ConversionFailed is the only one.

Attributes

Source
SchemaError.scala
Supertypes
trait Single
class Object
trait Matchable
class Any
Known subtypes
case class Message(source: DynamicOptic, details: String) extends Single

A failure described by the free text details.

A failure described by the free text details.

Unlike the other kinds, its message renders the path with DynamicOptic#toString, as in .format or .~ for a wrapped value, rather than with DynamicOptic#toScalaString, as in .format.when[Ebook] or .wrapped.

Attributes

Source
SchemaError.scala
Supertypes
trait Serializable
trait Product
trait Equals
trait Single
class Object
trait Matchable
class Any
Show all
case class MigrationError(source: DynamicOptic, kind: MigrationErrorKind) extends Single

A step of a schema migration failed at source; kind says how.

A step of a schema migration failed at source; kind says how.

Attributes

Source
SchemaError.scala
Supertypes
trait Serializable
trait Product
trait Equals
trait Single
class Object
trait Matchable
class Any
Show all

The kinds of MigrationError: PathNotFound (the path does not exist in the value), TypeMismatch (the value has the type actual where expected was required), MissingDefault (the field has no default value), TransformFailed and InvalidValue (with a reason), FieldNotFound, FieldAlreadyExists, CaseNotFound, and MandateFailed (making an optional field mandatory failed; not raised by the built-in migrations).

The kinds of MigrationError: PathNotFound (the path does not exist in the value), TypeMismatch (the value has the type actual where expected was required), MissingDefault (the field has no default value), TransformFailed and InvalidValue (with a reason), FieldNotFound, FieldAlreadyExists, CaseNotFound, and MandateFailed (making an optional field mandatory failed; not raised by the built-in migrations).

Attributes

Companion
trait
Source
SchemaError.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
sealed trait MigrationErrorKind

The ways a migration step can fail.

The ways a migration step can fail.

Attributes

Companion
object
Source
SchemaError.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
case class MissingField(source: DynamicOptic, fieldName: String) extends Single

The record at source has no field fieldName. The message is Missing field '' at:.

The record at source has no field fieldName. The message is Missing field '' at:.

Attributes

Source
SchemaError.scala
Supertypes
trait Serializable
trait Product
trait Equals
trait Single
class Object
trait Matchable
class Any
Show all
sealed trait Single

One failure: a message and the path of the place where it happened.

One failure: a message and the path of the place where it happened.

Attributes

Source
SchemaError.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
case class UnknownCase(source: DynamicOptic, caseName: String) extends Single

The variant at source has no case named caseName.

The variant at source has no case named caseName.

Attributes

Source
SchemaError.scala
Supertypes
trait Serializable
trait Product
trait Equals
trait Single
class Object
trait Matchable
class Any
Show all

Inherited and Abstract types

type MirroredElemLabels <: Tuple

The names of the product elements.

The names of the product elements.

Attributes

Inherited from:
Mirror
Source
Mirror.scala
type MirroredLabel <: String

The name of the type.

The name of the type.

Attributes

Inherited from:
Mirror
Source
Mirror.scala

Value members

Concrete methods

def apply(details: String): SchemaError

Creates a Message error with the free-text message details at the root path.

Creates a Message error with the free-text message details at the root path.

Attributes

Source
SchemaError.scala
def caseNotFound(path: DynamicOptic, caseName: String): SchemaError

Creates a MigrationError of kind CaseNotFound at path.

Creates a MigrationError of kind CaseNotFound at path.

Attributes

Source
SchemaError.scala
def conversionFailed(trace: List[Node], details: String): SchemaError

Creates a ConversionFailed error with the message details at the path trace.

Creates a ConversionFailed error with the message details at the path trace.

Attributes

Source
SchemaError.scala
def conversionFailed(contextMessage: String, cause: SchemaError): SchemaError

Creates a ConversionFailed error at the root that wraps cause. Its message is contextMessage followed by the messages of cause under Caused by:, and does not show the error's own path, even after atField.

Creates a ConversionFailed error at the root that wraps cause. Its message is contextMessage followed by the messages of cause under Caused by:, and does not show the error's own path, even after atField.

Attributes

Source
SchemaError.scala
def duplicatedField(trace: List[Node], fieldName: String): SchemaError

Creates a DuplicatedField error for the field fieldName that appears more than once in the record at the path trace.

Creates a DuplicatedField error for the field fieldName that appears more than once in the record at the path trace.

Attributes

Source
SchemaError.scala
def expectationMismatch(trace: List[Node], expectation: String): SchemaError

Creates an ExpectationMismatch error, for a value of the wrong shape, with the message expectation at the path trace.

Creates an ExpectationMismatch error, for a value of the wrong shape, with the message expectation at the path trace.

Attributes

Source
SchemaError.scala
def fieldAlreadyExists(path: DynamicOptic, fieldName: String): SchemaError

Creates a MigrationError of kind FieldAlreadyExists at path.

Creates a MigrationError of kind FieldAlreadyExists at path.

Attributes

Source
SchemaError.scala
def fieldNotFound(path: DynamicOptic, fieldName: String): SchemaError

Creates a MigrationError of kind FieldNotFound at path.

Creates a MigrationError of kind FieldNotFound at path.

Attributes

Source
SchemaError.scala
def invalidValue(path: DynamicOptic, reason: String): SchemaError

Creates a MigrationError of kind InvalidValue at path.

Creates a MigrationError of kind InvalidValue at path.

Attributes

Source
SchemaError.scala
def mandateFailed(path: DynamicOptic, reason: String): SchemaError

Creates a MigrationError of kind MandateFailed at path.

Creates a MigrationError of kind MandateFailed at path.

Attributes

Source
SchemaError.scala
def message(details: String, path: DynamicOptic = ...): SchemaError

Creates a Message error with the free-text message details at path, the root by default.

Creates a Message error with the free-text message details at path, the root by default.

Attributes

Source
SchemaError.scala

Creates a MigrationError of kind kind at path.

Creates a MigrationError of kind kind at path.

Attributes

Source
SchemaError.scala
def missingDefault(path: DynamicOptic, fieldName: String): SchemaError

Creates a MigrationError of kind MissingDefault at path.

Creates a MigrationError of kind MissingDefault at path.

Attributes

Source
SchemaError.scala
def missingField(trace: List[Node], fieldName: String): SchemaError

Creates a MissingField error for the absent field fieldName of the record at the path trace.

Creates a MissingField error for the absent field fieldName of the record at the path trace.

Attributes

Source
SchemaError.scala

Creates a MigrationError of kind PathNotFound at path.

Creates a MigrationError of kind PathNotFound at path.

Attributes

Source
SchemaError.scala
def transformFailed(path: DynamicOptic, reason: String): SchemaError

Creates a MigrationError of kind TransformFailed at path.

Creates a MigrationError of kind TransformFailed at path.

Attributes

Source
SchemaError.scala
def typeMismatch(path: DynamicOptic, expected: String, actual: String): SchemaError

Creates a MigrationError of kind TypeMismatch at path.

Creates a MigrationError of kind TypeMismatch at path.

Attributes

Source
SchemaError.scala
def unknownCase(trace: List[Node], caseName: String): SchemaError

Creates an UnknownCase error for the case caseName that the variant at the path trace does not have.

Creates an UnknownCase error for the case caseName that the variant at the path trace does not have.

Attributes

Source
SchemaError.scala
def validationFailed(message: String): SchemaError

Creates an error with the message message at the root path, for a value that breaks a rule. It is the same as conversionFailed(Nil, message).

Creates an error with the message message at the root path, for a value that breaks a rule. It is the same as conversionFailed(Nil, message).

Throw it from the to function of Schema#transform, or from a smart constructor that to calls, to reject a value while decoding. The decoder keeps only the message, at a path that ends in .wrapped, the step into the transformed value: Schema#fromDynamicValue returns it as a new ConversionFailed, and the JSON codec as a new ExpectationMismatch.

final case class Title(value: String)
object Title {
 def make(value: String): Title =
   if (value.trim.nonEmpty) Title(value)
   else throw SchemaError.validationFailed("title must not be blank")

 implicit val schema: Schema[Title] = Schema[String].transform(make, _.value)
}

val title = "\"Zionomicon\"".fromJson[Title] // Right(Title(Zionomicon))
val blank = "\"  \"".fromJson[Title]
// Left(zio.blocks.schema.SchemaError: title must not be blank at: .wrapped)

Attributes

See also
Source
SchemaError.scala