silk.schema.issue.

The problems a schema reports, and where in the value 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 to show a person what failed and where, such as port: between 1 and 65535.

Details#

An Issue is a small copyable value: a IssueReason, one line of static text that names what was expected, and the byte offset of the problem when the format knows it. A SchemaError adds the path from the root value to the part that failed.

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

Public declarations: 4.

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.

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.

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 "between 1 and 65535". offset is the byte offset of the problem in the input, when the format knows it.

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 offset#

silk
pub offset: Option<usize>

The byte offset of the problem in the input, 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 offset.

Associated function at#

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

Returns an issue at byte offset of the input.

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.

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: ..., offset: ... }.

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.

SchemaError#

silk
pub struct SchemaError

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

Details#

path names struct fields by their Silk names and list elements by their index, as settings.ports[2]. It is empty when the root value itself failed.

Field path#

silk
pub path: String

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

Field issue#

silk
pub issue: Issue

The problem.

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: ... }.

SchemaErrors#

silk
pub struct SchemaErrors

Every problem found while reading one value, in the order they were found.

Details#

silk.schema.json.SchemaJson.decodeAll reports it. Every failed check is listed, and reading stops at the first value that does not have the expected shape, which is listed last.

Field errors#

silk
pub errors: List<SchemaError>

The problems, never empty.

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: [...] }.

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