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#
pub enum IssueReasonWhy a value could not be read, written, or accepted.
InvalidType#
InvalidTypeThe input holds another kind of value, such as text where a number was expected.
InvalidValue#
InvalidValueThe input holds the right kind of value, but not one the type accepts, such as 300 for a
u8.
MissingKey#
MissingKeyA required key is absent.
InvalidSyntax#
InvalidSyntaxThe input is not well formed, such as JSON without a closing quote.
CheckFailed#
CheckFailedA check of the value failed.
UnknownVariant#
UnknownVariantThe text names no variant of the union.
Issue#
pub struct IssueOne 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#
pub reason: IssueReasonWhy the value was rejected.
Field expected#
pub expected: string<'static>What the schema expected, as one line of text for a person.
Field offset#
pub offset: Option<usize>The byte offset of the problem in the input, if known.
Implementation Copy for Issue#
impl Copy for IssueImplementation Issue#
impl IssueAssociated function make#
pub fn make(reason: IssueReason, expected: string<'static>) -> IssueReturns an issue with reason and expected, and no offset.
Associated function at#
pub fn at(reason: IssueReason, expected: string<'static>, offset: usize) -> IssueReturns an issue at byte offset of the input.
Associated function invalidType#
pub fn invalidType(expected: string<'static>) -> IssueReturns an issue for input that holds another kind of value than expected.
Associated function invalidValue#
pub fn invalidValue(expected: string<'static>) -> IssueReturns an issue for a value of the right kind that the type does not accept.
Associated function missingKey#
pub fn missingKey() -> IssueReturns an issue for a required key that is absent.
Associated function checkFailed#
pub fn checkFailed(expected: string<'static>) -> IssueReturns an issue for a check that failed. expected is the check's message.
Implementation Debug for Issue#
impl Debug for IssueOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the fields, as Issue { reason: ..., expected: ..., offset: ... }.
Implementation Debug for IssueReason#
impl Debug for IssueReasonOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the name of the reason, such as MissingKey.
SchemaError#
pub struct SchemaErrorA 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#
pub path: StringThe path from the root value to the part that failed, such as settings.ports[2].
Field issue#
pub issue: IssueThe problem.
Implementation Debug for SchemaError#
impl Debug for SchemaErrorOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the fields, as SchemaError { path: ..., issue: ... }.
SchemaErrors#
pub struct SchemaErrorsEvery 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#
pub errors: List<SchemaError>The problems, never empty.
Implementation Debug for SchemaErrors#
impl Debug for SchemaErrorsOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites 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.