Core.defect: def of bend-schema-lib@0.4.1.0 Import: import bend-schema-lib@0.4.1.0/core.bend as Core Lines 1194-1305 of bend-schema-lib@0.4.1.0/core.bend: https://jend.leeeet.dev/read.txt?path=bend-schema-lib@0.4.1.0/core.bend&start_line=1194&end_line=1305 import Base def defect(~rule: Nat -> Raw -> Maybe<&2, Err>, s: Schema, r: Raw, +prev: Maybe<&2, Nat>, p: List<&2, Step>) -> Maybe<&2, Why>: match s r p: case SJson{} RJson{value} q: guard(Bool.not(valid_json(value)), at_end(NotJson{}, q)) case SJson{} x q: at_end(missing_or(x, NotJson{}), q) case SInt{} x q: int_defect(x, q) case SIntIn{+lo, +hi} x q: int_in_defect(lo, hi, x, q) case SNat{} x q: nat_defect(x, q) case SStr{} x q: str_defect(x, q) case SNatIn{+lo, +hi} x q: nat_in_defect(lo, hi, x, q) case SStrLen{+lo, +hi, +s2} +x +q: pick_why(conforms(~rule, s2, x, prev), rule_defect(len_err(lo, hi, x), q), defect(~rule, s2, x, prev, q)) case SListLen{+lo, +hi, +s2} +r +q: # The count came first in check, so the count's own error is the one # reported here exactly when there was one to report -- for a list out of # bounds and for a value that is not a list at all (list_len_ok is False # for both, and count_err reported something for both). pick_why(Bool.not(list_len_ok(lo, hi, r)), rule_defect(count_err(lo, hi, r), q), defect(~rule, s2, r, None{}, q)) case SOpt{inner} RNull{} q: None{} case SOpt{inner} x q: defect(~rule, inner, x, None{}, q) case SOptional{inner} RMissing{} q: None{} # absent is not wrong, at this path or below it case SOptional{inner} x q: defect(~rule, inner, x, None{}, q) case SList{e} RNil{} q: None{} case SList{e} RCons{h, t} AtIndex{0n} <> q: defect(~rule, e, h, None{}, q) case SList{+e} RCons{h, t} AtIndex{1n+j} <> q: guard(conforms(~rule, e, h, None{}), defect(~rule, SList{e}, t, None{}, AtIndex{j} <> q)) case SList{+e} RCons{h, t} q: guard(conforms(~rule, e, h, None{}), defect(~rule, SList{e}, t, None{}, q)) case SList{e} x q: not_list(x, q) case SField{+name, fs, rest} REnd{} AtField{0n, n} <> q: guard(String.eq(n, name), defect(~rule, fs, RMissing{}, None{}, q)) case SField{+name, fs, rest} REnd{} AtField{1n+k, n} <> q: guard(conforms(~rule, fs, RMissing{}, None{}), defect(~rule, rest, REnd{}, None{}, AtField{k, n} <> q)) case SField{+name, fs, rest} REnd{} q: guard(conforms(~rule, fs, RMissing{}, None{}), defect(~rule, rest, REnd{}, None{}, q)) case SField{+name, fs, rest} RKey{+k, +v, +o} AtField{0n, n} <> +q: pick_why(Bool.not(key_once(name, RKey{k, v, o})), at_end(RepeatedKey{name}, q), guard(String.eq(n, name), defect(~rule, fs, lookup(name, RKey{k, v, o}), None{}, q))) case SField{+name, fs, rest} RKey{+k, +v, +o} AtField{1n+j, n} <> q: guard(conforms(~rule, fs, lookup(name, RKey{k, v, o}), None{}), defect(~rule, rest, RKey{k, v, o}, None{}, AtField{j, n} <> q)) case SField{+name, fs, rest} RKey{+k, +v, +o} q: guard(conforms(~rule, fs, lookup(name, RKey{k, v, o}), None{}), defect(~rule, rest, RKey{k, v, o}, None{}, q)) case SField{name, fs, rest} x q: not_object(x, q) case SEnd{} REnd{} q: None{} case SEnd{} RKey{k, v, o} q: None{} case SEnd{} x q: not_object(x, q) case SRule{+s2, +tag} +x +q: pick_why(conforms(~rule, s2, x, prev), rule_defect(rule(tag, x), q), defect(~rule, s2, x, prev, q)) case SStrict{+s2} +x +q: pick_why(conforms(~rule, s2, x, prev), extra_defect(key_names(s2), x, q), defect(~rule, s2, x, prev, q)) case STagged{+k, +n, cs, rest} +x +q: pick_why(is_tag(k, n, x), first_why(tag_key_defect(Bool.not(key_once(k, x)), k, q), defect(~rule, cs, drop_key(k, x), None{}, q)), defect(~rule, rest, x, None{}, q)) case STagEnd{k} x q: tag_defect(k, x, q) case SBool{} x q: bool_defect(x, q) case STrue{} x q: true_defect(x, q) case SEnum{names} x q: enum_defect(names, x, q) case SVariant{+name, +vs, +rest} REnd{} AtField{1n+j, n} <> q: defect(~rule, rest, REnd{}, None{}, AtField{j, n} <> q) case SVariant{+name, +vs, +rest} REnd{} q: defect(~rule, rest, REnd{}, None{}, q) case SVariant{+name, +vs, +rest} RKey{+k, +v, +o} AtField{0n, +n} <> +q: pick_why(is_missing(lookup(name, RKey{k, v, o})), defect(~rule, rest, RKey{k, v, o}, None{}, AtField{0n, n} <> q), pick_why(Bool.not(key_once(name, RKey{k, v, o})), at_end(RepeatedKey{name}, q), guard(String.eq(n, name), defect(~rule, vs, lookup(name, RKey{k, v, o}), None{}, q)))) case SVariant{+name, +vs, +rest} RKey{+k, +v, +o} AtField{1n+j, +n} <> +q: pick_why(is_missing(lookup(name, RKey{k, v, o})), defect(~rule, rest, RKey{k, v, o}, None{}, AtField{j, n} <> q), guard(conforms(~rule, vs, lookup(name, RKey{k, v, o}), None{}), dup_defect(rest, RKey{k, v, o}, AtField{j, n} <> q))) case SVariant{+name, +vs, +rest} RKey{+k, +v, +o} +q: pick_why(is_missing(lookup(name, RKey{k, v, o})), defect(~rule, rest, RKey{k, v, o}, None{}, q), None{}) case SVariant{+name, +vs, +rest} x q: not_object(x, q) case SVEnd{} REnd{} q: no_variant(q) case SVEnd{} RKey{k, v, o} q: no_variant(q) case SVEnd{} x q: not_object(x, q) case STuple{ts, rest} RCons{h, t} AtIndex{0n} <> q: defect(~rule, ts, h, None{}, q) case STuple{+ts, rest} RCons{h, t} AtIndex{1n+j} <> q: guard(conforms(~rule, ts, h, None{}), defect(~rule, rest, t, None{}, AtIndex{j} <> q)) case STuple{+ts, rest} RCons{h, t} q: guard(conforms(~rule, ts, h, None{}), defect(~rule, rest, t, None{}, q)) case STuple{ts, rest} RNil{} q: at_end(TooShort{}, q) case STuple{ts, rest} x q: not_list(x, q) case STEnd{} RNil{} q: None{} case STEnd{} RCons{h, t} q: at_end(TooLong{}, q) case STEnd{} x q: not_list(x, q) case SEither{+l, +r} +x +q: pick_why(has_kind(l, kind_of(x)), defect(~rule, l, x, prev, q), pick_why(has_kind(r, kind_of(x)), defect(~rule, r, x, prev, q), at_end(missing_or(x, no_alt(SEither{l, r})), q))) Uses (45): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.not https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Maybe https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String.eq https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=Err https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=Raw https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=Schema https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=Step https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=Why https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=at_end https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=bool_defect https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=conforms https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=count_err https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=drop_key https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=dup_defect https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=enum_defect https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=extra_defect https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=first_why https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=guard https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=has_kind https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=int_defect https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=int_in_defect https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=is_missing https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=is_tag https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=key_names https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=key_once https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=kind_of https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=len_err https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=list_len_ok https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=lookup https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=missing_or https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=nat_defect https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=nat_in_defect https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=no_alt https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=no_variant https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=not_list https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=not_object https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=pick_why https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=rule_defect https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=str_defect https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=tag_defect https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=tag_key_defect https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=true_defect https://jend.leeeet.dev/definition.txt?path=bend-schema-lib@0.4.1.0/core.bend&name=valid_json