Function prettyPrintFailureError

  • Pretty prints errors with the rational that multiple errors can occur in an array, or an object.

    A top level decoding error always starts with "$root" (not to be confused with a field called "root")

    asString.decode(1)
    // $root: expected string but got number

    An array can return multiple errors

    asArray(asString).decode(["foo", 1, "bar", null])
    // $root[1]: expected string but got number
    // $root[3]: expected string but got null

    An object can return multiple errors

    const decoder = asObject.withField(
    "foo",
    asArray(
    asObject.withField("bar", asString)
    )
    )

    decoder.decode({ foo: [ {bar: "buzz"}, {fizz: "foo"}, {bar: 2} ] })
    // $root.foo[1].bar: expected string but got undefined
    // $root.foo[2].bar: expected string but got number

    Parameters

    Returns string

    pretty printed error string

Generated using TypeDoc