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#
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.
UnexpectedKey#
UnexpectedKeyAn object has a key that its type does not name, and its spec is Spec.strict.
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.
Reported#
ReportedA part of the value failed and its problems are already recorded, as decodeAll does. A
report never lists it.
ValueKind#
pub enum ValueKindThe kind of value found in the input.
Unknown#
UnknownNot known, or not one value.
Text#
TextText, such as a JSON string.
Number#
NumberA number.
Boolean#
Booleantrue or false.
Null#
NullA null value.
Bytes#
BytesBinary data, such as a MessagePack bin value.
List#
ListA list, such as a JSON array.
Object#
ObjectAn object.
Missing#
MissingNothing: the key is absent.
Span#
pub struct SpanA range of bytes of the input, from start up to but not including end.
Field start#
pub start: usizeThe first byte.
Field end#
pub end: usizeThe byte after the last one.
Implementation Copy for Span#
impl Copy for SpanIssue#
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
"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#
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 found#
pub found: ValueKindThe kind of value the input held.
Field span#
pub span: Option<Span>The bytes of the input the problem is about, 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 position.
Associated function at#
pub fn at(reason: IssueReason, expected: string<'static>, found: ValueKind, span: Span) -> IssueReturns an issue about the input bytes span, which hold a value of kind found.
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.
Method locate#
pub fn locate(self: Self, span: Option<Span>, found: ValueKind) -> IssueReturns the issue at span, holding a value of kind found, unless it already has a span.
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: ..., found: ..., span: ... }.
Implementation Debug for Span#
impl Debug for SpanOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the fields, as Span { start: ..., end: ... }.
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.
Implementation IssueReason#
impl IssueReasonMethod name#
pub fn name(self: Self) -> string<'static>Returns the name of the reason, such as "MissingKey".
Implementation ValueKind#
impl ValueKindMethod noun#
pub fn noun(self: Self) -> string<'static>Returns how a person names the kind, such as "text" or "a list".
Implementation Debug for ValueKind#
impl Debug for ValueKindOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the name of the kind, such as Text.
SchemaError#
pub struct SchemaErrorA 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#
pub path: SchemaPathThe path from the root value to the part that failed, such as settings.ports[2].
Field issue#
pub issue: IssueThe problem.
Field got#
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#
impl Debug for SchemaErrorOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the fields, as SchemaError { path: ..., issue: ..., got: ... }.
MAX_PROBLEMS#
pub const MAX_PROBLEMS: usizeThe most problems one decodeAll records; later ones are counted in SchemaErrors.dropped.
SchemaErrors#
pub struct SchemaErrorsEvery 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#
pub errors: List<SchemaError>The problems, never empty.
Field dropped#
pub dropped: usizeHow many more problems were found after the first MAX_PROBLEMS.
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: [...], 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.