Open History to see the last commit
1import { errorsHidden } from './errorsHidden'
2import { schemaErrorOnUnmountedField } from './schemaErrorOnUnmountedField'
3import { serverErrorOnUnmountedField } from './serverErrorOnUnmountedField'
4import type { FieldErrorDebugCase, FieldErrorDebugCaseContext } from './types'
5import type { FieldErrorDebugSuspicion } from '../../../eventClientTypes'
6β
7export type { FieldErrorDebugCase } from './types'
8β
9/**
10 * The order of these cases is important.
11 * They are evaluated in order, and the first one that matches will be used.
12 *
13 * The most specific cases should be first.
14 */
15const fieldErrorDebugCases = [
16 schemaErrorOnUnmountedField,
17 serverErrorOnUnmountedField,
18 errorsHidden,
19] satisfies ReadonlyArray<FieldErrorDebugCase>
20β
21export function getFieldErrorDebugSuspicions(
22 context: FieldErrorDebugCaseContext,
23 cases: ReadonlyArray<FieldErrorDebugCase> = fieldErrorDebugCases,
24): Array<FieldErrorDebugSuspicion> {
25 const suspicions: Array<FieldErrorDebugSuspicion> = []
26β
27 for (const debugCase of cases) {
28 const suspicion = debugCase.evaluate(context)
29 if (suspicion) suspicions.push(suspicion)
30 }
31β
32 return suspicions
33}