From 18943f702c24dfd8f9e1176660e45a008c619e8e Mon Sep 17 00:00:00 2001 From: Aarushsr12 Date: Fri, 20 Feb 2026 16:40:33 +0530 Subject: [PATCH] fix: get path from typebox error --- .../actions/local-sync/common-utils.ts | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/renderer/actions/local-sync/common-utils.ts b/src/renderer/actions/local-sync/common-utils.ts index 2bd1e27..28f3926 100644 --- a/src/renderer/actions/local-sync/common-utils.ts +++ b/src/renderer/actions/local-sync/common-utils.ts @@ -83,19 +83,22 @@ export function createFsResource(params: { } } +export type ValidationErrorEntry = { path: string; message: string }; + /** * Collects all error messages from TypeBox validation errors */ -function collectVerboseErrors(TypeboxError: Iterable): string[] { - const messages: string[] = []; + +function collectVerboseErrors(TypeboxError: Iterable): ValidationErrorEntry[] { + const messages: ValidationErrorEntry[] = []; for (const nestedError of TypeboxError) { - messages.push(nestedError.message); - if (nestedError.errors && nestedError.errors.length > 0) { + const path = nestedError.path !== undefined && nestedError.path !== "" ? nestedError.path : ""; + messages.push({ path, message: nestedError.message }); + if (nestedError.errors && nestedError.errors.length > 0) { nestedError.errors.forEach((subIterator) => { const subErrors = Array.from(subIterator); - if (subErrors.length > 0) { const nestedMessages = collectVerboseErrors(subErrors); messages.push(...nestedMessages); @@ -107,21 +110,17 @@ function collectVerboseErrors(TypeboxError: Iterable): string[] { return messages; } -/** - * Collects all validation errors and their messages. - * Returns the first error as heading and remaining errors as additional context. - */ function formatValidationErrors(validator: TSchema, content: any): { error: any; - heading: string; - additionalErrors: string[]; + heading: ValidationErrorEntry[]; + additionalErrors: ValidationErrorEntry[]; } { const allErrors = [...Value.Errors(validator, content)]; const nestedErrorMessages = collectVerboseErrors(allErrors); - + return { error: allErrors[0], - heading: nestedErrorMessages[0] || "Validation error", + heading: nestedErrorMessages, additionalErrors: nestedErrorMessages.slice(1), }; } @@ -141,8 +140,13 @@ export function parseRaw( content: parsedContent, } as ContentParseResult>; // Casting because TS was not able to infer from fn result type } catch { - const { error, heading, additionalErrors } = formatValidationErrors(validator, content); - captureException(heading, { extra: { additionalErrors } }); + const { error, heading, additionalErrors } = formatValidationErrors(validator, content); + + const headingMessage = + heading.length > 0 + ? (heading[0].path ? `[${heading[0].path}] ` : "") + heading[0].message + : "Validation failed"; + captureException(headingMessage, { extra: { additionalErrors, allErrors: heading } }); return { type: "error",