pedantic/report

Types

Represents a structural or constraint error.

pub type Error {
  Error(
    path: List(PathSegment),
    message: String,
    kind: ErrorKind,
    actual: dynamic.Dynamic,
  )
}

Constructors

  • Error(
      path: List(PathSegment),
      message: String,
      kind: ErrorKind,
      actual: dynamic.Dynamic,
    )

    Arguments

    path

    The location of the error.

    message

    Explicit, human-readable message.

    kind

    The classification of the failure.

    actual

    The raw dynamic value that caused the error.

The kind of validation or parsing error that occurred.

pub type ErrorKind {
  WrongType(expected: String, actual: String)
  MissingField
  UnknownField(String)
  TooSmall(Int)
  TooLarge(Int)
  TooShort(Int)
  TooLong(Int)
  InvalidEnum(List(String))
  InvalidFormat(String)
  Custom(String)
}

Constructors

  • WrongType(expected: String, actual: String)

    The value is of the wrong type.

  • MissingField

    A required field is missing from an object.

  • UnknownField(String)

    An unknown field was present in the input.

  • TooSmall(Int)

    A numeric value is smaller than the allowed limit.

  • TooLarge(Int)

    A numeric value is larger than the allowed limit.

  • TooShort(Int)

    A string, list, or binary is too short.

  • TooLong(Int)

    A string, list, or binary is too long.

  • InvalidEnum(List(String))

    The value did not match any of the allowed enum options.

  • InvalidFormat(String)

    The value did not conform to the expected format.

  • Custom(String)

    A user-defined custom error.

pub type IssueKind =
  ErrorKind

Metadata holding schema decoration information.

pub type Metadata {
  Metadata(
    title: option.Option(String),
    description: option.Option(String),
    example: option.Option(dynamic.Dynamic),
  )
}

Constructors

A path is a list of segments that represents the exact location of a value.

pub type Path =
  List(PathSegment)

A segment in the path to a value within a nested data structure.

pub type PathSegment {
  Field(String)
  Index(Int)
}

Constructors

  • Field(String)

    A field key in an object or dictionary.

  • Index(Int)

    An index offset in an array or list.

The accumulated logs and results of a codec transformation.

pub type Report {
  Report(errors: List(Error), warnings: List(Warning))
}

Constructors

  • Report(errors: List(Error), warnings: List(Warning))

    Arguments

    errors

    The list of errors encountered.

    warnings

    The list of warnings encountered.

A field in an object type graph.

pub type TypeField {
  TypeField(name: String, graph: TypeGraph)
}

Constructors

The inspectable type graph representing the shape of a codec.

pub type TypeGraph {
  PrimitiveInt
  PrimitiveString
  PrimitiveBool
  PrimitiveFloat
  List(TypeGraph)
  Option(TypeGraph)
  Object(name: String, fields: List(TypeField))
  Dict(value: TypeGraph)
  Annotated(graph: TypeGraph, meta: Metadata)
  Union(options: List(TypeGraph))
}

Constructors

pub type ValidationIssue =
  Error
pub type ValidationReport =
  Report
pub type ValidationWarning =
  Warning

Represents a non-fatal warning during decoding.

pub type Warning {
  Warning(path: List(PathSegment), kind: WarningKind)
}

Constructors

  • Warning(path: List(PathSegment), kind: WarningKind)

    Arguments

    path

    The location of the warning.

    kind

    The classification of the warning.

The kind of warning that occurred.

pub type WarningKind {
  DiscardedUnknownField(String)
}

Constructors

  • DiscardedUnknownField(String)

    An unknown field was discarded from the object.

Values

pub fn add_error(report: Report, error: Error) -> Report

Adds an error to a report.

pub fn add_warning(report: Report, warning: Warning) -> Report

Adds a warning to a report.

pub fn default_message(kind: ErrorKind) -> String

Returns a human-readable default message for any ErrorKind.

pub fn dynamic_from(a: any) -> dynamic.Dynamic
pub fn make_error(
  path: List(PathSegment),
  kind: ErrorKind,
  actual: dynamic.Dynamic,
) -> Error

Constructs a ValidationIssue/Error with a default message.

pub fn merge(a: Report, b: Report) -> Report

Merges two reports together.

pub fn new() -> Report

Creates a new, empty report.

pub fn path_to_string(path: List(PathSegment)) -> String

Converts a path to a dotted string representation.

pub fn prefix_path(
  report: Report,
  segment: PathSegment,
) -> Report

Prefixes the path of all errors and warnings in a report with a segment.

pub fn to_dict(report: Report) -> dict.Dict(String, List(String))

Converts a report into a dictionary mapping dotted paths to lists of human-readable error messages.

Search Document