silk.schema.issue.

The problems a schema reports, and where in the value and the input they happened.

When to use#

Match on Issue when a codec, a check, or a format reader rejects input. Read SchemaError from silk.schema.json.SchemaJson.decode, or SchemaErrors from SchemaJson.decodeAll, and show them with silk.schema.report.SchemaReport.

Details#

An Issue is a small copyable value: an IssueReason, one line of static text that names what was expected, the kind of value found, and the Span of input bytes it is about when the format knows it. A SchemaError adds the SchemaPath from the root value to the part that failed. Nothing copies the input: a report cuts the found value out of the input by its span.

Import as Issue with import silk.schema.issue { Issue }.

Public declarations: 7.

IssueReason#

silk
pub enum IssueReason

Why a value could not be read, written, or accepted.

InvalidType#

silk
InvalidType

The input holds another kind of value, such as text where a number was expected.

InvalidValue#

silk
InvalidValue

The input holds the right kind of value, but not one the type accepts, such as 300 for a u8.

MissingKey#

silk
MissingKey

A required key is absent.

UnexpectedKey#

silk
UnexpectedKey

An object has a key that its type does not name, and its spec is Spec.strict.

InvalidSyntax#

silk
InvalidSyntax

The input is not well formed, such as JSON without a closing quote.

CheckFailed#

silk
CheckFailed

A check of the value failed.

UnknownVariant#

silk
UnknownVariant

The text names no variant of the union.

Reported#

silk
Reported

A part of the value failed and its problems are already recorded, as decodeAll does. A report never lists it.

ValueKind#

silk
pub enum ValueKind

The kind of value found in the input.

Unknown#

silk
Unknown

Not known, or not one value.

Text#

silk
Text

Text, such as a JSON string.

Number#

silk
Number

A number.

Boolean#

silk
Boolean

true or false.

Null#

silk
Null

A null value.

Bytes#

silk
Bytes

Binary data, such as a MessagePack bin value.

List#

silk
List

A list, such as a JSON array.

Object#

silk
Object

An object.

Missing#

silk
Missing

Nothing: the key is absent.

Span#

silk
pub struct Span

A range of bytes of the input, from start up to but not including end.

Field start#

silk
pub start: usize

The first byte.

Field end#

silk
pub end: usize

The byte after the last one.

Implementation Copy for Span#

silk
impl Copy for Span

Issue#

silk
pub struct Issue

One problem found while reading, writing, or checking a value.

Details#

expected is one line of static text that says what the schema wanted, such as "a number" or "an integer from 1 to 65535". found is the kind of value the input held, and span the bytes of the input the problem is about, when the format knows them.

Field reason#

silk
pub reason: IssueReason

Why the value was rejected.

Field expected#

silk
pub expected: string<'static>

What the schema expected, as one line of text for a person.

Field found#

silk
pub found: ValueKind

The kind of value the input held.

Field span#

silk
pub span: Option<Span>

The bytes of the input the problem is about, if known.

Implementation Copy for Issue#

silk
impl Copy for Issue

Implementation Issue#

silk
impl Issue

Associated function make#

silk
pub fn make(reason: IssueReason, expected: string<'static>) -> Issue

Returns an issue with reason and expected, and no position.

Associated function at#

silk
pub fn at(reason: IssueReason, expected: string<'static>, found: ValueKind, span: Span) -> Issue

Returns an issue about the input bytes span, which hold a value of kind found.

Associated function invalidType#

silk
pub fn invalidType(expected: string<'static>) -> Issue

Returns an issue for input that holds another kind of value than expected.

Associated function invalidValue#

silk
pub fn invalidValue(expected: string<'static>) -> Issue

Returns an issue for a value of the right kind that the type does not accept.

Associated function missingKey#

silk
pub fn missingKey() -> Issue

Returns an issue for a required key that is absent.

Associated function checkFailed#

silk
pub fn checkFailed(expected: string<'static>) -> Issue

Returns an issue for a check that failed. expected is the check's message.

Method locate#

silk
pub fn locate(self: Self, span: Option<Span>, found: ValueKind) -> Issue

Returns the issue at span, holding a value of kind found, unless it already has a span.

Implementation Debug for Issue#

silk
impl Debug for Issue

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the fields, as Issue { reason: ..., expected: ..., found: ..., span: ... }.

Implementation Debug for Span#

silk
impl Debug for Span

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the fields, as Span { start: ..., end: ... }.

Implementation Debug for IssueReason#

silk
impl Debug for IssueReason

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the name of the reason, such as MissingKey.

Implementation IssueReason#

silk
impl IssueReason

Method name#

silk
pub fn name(self: Self) -> string<'static>

Returns the name of the reason, such as "MissingKey".

Implementation ValueKind#

silk
impl ValueKind

Method noun#

silk
pub fn noun(self: Self) -> string<'static>

Returns how a person names the kind, such as "text" or "a list".

Implementation Debug for ValueKind#

silk
impl Debug for ValueKind

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the name of the kind, such as Text.

SchemaError#

silk
pub struct SchemaError

A rejected value: the problem, and the path from the root value to the part that failed.

Details#

path keeps its segments, so it renders with wire names for a person (SchemaPath.text), as a JSON Pointer for a tool (SchemaPath.pointer), or with Silk names (SchemaPath.names). It is empty when the root value itself failed.

Field path#

silk
pub path: SchemaPath

The path from the root value to the part that failed, such as settings.ports[2].

Field issue#

silk
pub issue: Issue

The problem.

Field got#

silk
pub got: Option<String>

The value found, when the input bytes do not hold it, such as the unknown variant name silk.schema.json.SchemaJson.decodeVariant was given apart from its arguments.

Implementation Debug for SchemaError#

silk
impl Debug for SchemaError

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the fields, as SchemaError { path: ..., issue: ..., got: ... }.

MAX_PROBLEMS#

silk
pub const MAX_PROBLEMS: usize

The most problems one decodeAll records; later ones are counted in SchemaErrors.dropped.

SchemaErrors#

silk
pub struct SchemaErrors

Every problem found while reading one value, in input order.

Details#

silk.schema.json.SchemaJson.decodeAll reports it. A part that fails is recorded and skipped, and reading goes on with its next sibling, so one call lists every problem in the input, up to MAX_PROBLEMS.

Field errors#

silk
pub errors: List<SchemaError>

The problems, never empty.

Field dropped#

silk
pub dropped: usize

How many more problems were found after the first MAX_PROBLEMS.

Implementation Debug for SchemaErrors#

silk
impl Debug for SchemaErrors

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the problems, as SchemaErrors { errors: [...], dropped: ... }.

Category: Data formats.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.

View the source of this page