### Description When a ValidationError is nested (its has children) producing an error message based on the children state requires some traveseal function. ### Proposed solution Add a utility / a method on each ValidationError which performs a BFS traverse including the path ```js const traverseValidationError = (root: ValidationError, cb: (path: string, error: ValidationError) => void) => { const queue = [{ error: root, path: root.property }]; while (queue.length > 0) { const item = queue.shift(); if (item !== undefined) { const { error, path } = item; if (error.children?.length) { for (const childError of error.children) { const childPath = `${path}.${childError.property}`; queue.push({ error: childError, path: childPath }); } } cb(path, error); } } }; ``` Note that the above function doesn't evaluate whether a proprety is number, and will produce > some_array.1.some_property instead of some_array.[1].some_property
Activity
[-]feature: traverse errors[/-][+]feature: traverse ValidationError.children[/+]braaar commentedon Jan 11, 2024
I'm moving this to the discussion tab, as we are trying to keep the issue count low. Please see this issue for an explanation.