MCPcopy Create free account
hub / github.com/arktypeio/arktype / ArkErrors

Class ArkErrors

ark/schema/shared/issuesLean.ts:130–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128const Issues: new () => Issues = (
129 readsErrors ?
130 class ArkErrors implements FailureContext {
131 _: ArkIssue[] = []
132 _p: PropertyKey[] = []
133
134 get count(): number {
135 return this._.length
136 }
137
138 get issues(): readonly WrittenIssue[] {
139 return serializableIssues(this._)
140 }
141
142 _e(
143 data: unknown,
144 code: ArkErrorCode,
145 expected?: string,
146 message?: string,
147 text?: SiteContext["text"]
148 ): true | undefined {
149 this._.push({ code, path: this._p.slice(), data, expected, message })
150 if (callsSiteText) text?.(this._[this._.length - 1])
151 return undefined
152 }
153
154 _k(
155 apply: CompactApply,
156 data: unknown,
157 key: PropertyKey,
158 ...missing: MissingText
159 ): boolean | undefined {
160 this._p.push(key)
161 const stops =
162 missing.length && !(key in (data as object)) ?
163 this._e(data, "required", ...missing)
164 : !apply((data as Keyed)[key], this)
165 this._p.pop()
166 return stops
167 }
168
169 get summary(): string {
170 return this._.map(issueLineOf).join("\n")
171 }
172
173 summaryIn(locale?: unknown): string {
174 refuseLocale(locale)
175 return this.summary
176 }
177
178 // as issues.ts's, an instance of TraversalError wherever it's kept
179 throw(): never {
180 if (namesTraversalError) throw new ThrownIssues(this as never)
181 if (mayDefineTraversalError && definedThrown)
182 throw new definedThrown(this as never)
183 const thrown = Error(this.summary)
184 thrown.name = "TraversalError"
185 throw Object.defineProperty(thrown, "arkErrors", { value: this })
186 }
187

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected