Skip to content

Comments

[ONCALL-313] fix: get path from type-box error#298

Open
Aarushsr12 wants to merge 1 commit intomasterfrom
ONCALL-313
Open

[ONCALL-313] fix: get path from type-box error#298
Aarushsr12 wants to merge 1 commit intomasterfrom
ONCALL-313

Conversation

@Aarushsr12
Copy link
Contributor

@Aarushsr12 Aarushsr12 commented Feb 20, 2026

Summary by CodeRabbit

  • Refactor
    • Enhanced validation error handling to provide more detailed error information, including specific paths and messages for validation failures.

@linear
Copy link

linear bot commented Feb 20, 2026

@coderabbitai
Copy link

coderabbitai bot commented Feb 20, 2026

Walkthrough

This pull request refactors error handling in the TypeBox validation pipeline. A new ValidationErrorEntry type is introduced to structure errors with path and message fields. The collectVerboseErrors function is updated to return an array of structured error entries instead of plain strings. The formatValidationErrors function is modified to return organized objects containing heading and additionalErrors as error entry arrays. Finally, parseRaw error handling is adjusted to compute a heading message from the first error entry and aggregate error context accordingly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: extracting and handling the path property from TypeBox validation errors in the error collection and formatting logic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ONCALL-313

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (3)
src/renderer/actions/local-sync/common-utils.ts (3)

113-126: heading is misleadingly named — it contains all errors, not a heading.

heading is assigned the full nestedErrorMessages array (line 123), while additionalErrors is nestedErrorMessages.slice(1) (line 124). This makes additionalErrors a strict subset of heading, and the name heading suggests a single summary or the first error, not the complete list.

Consider renaming for clarity and removing the redundancy:

♻️ Suggested refactor
 function formatValidationErrors(validator: TSchema, content: any): {
   error: any;
-  heading: ValidationErrorEntry[];
-  additionalErrors: ValidationErrorEntry[];
+  allErrors: ValidationErrorEntry[];
 } {
   const allErrors = [...Value.Errors(validator, content)];
   const nestedErrorMessages = collectVerboseErrors(allErrors);

   return {
     error: allErrors[0],
-    heading: nestedErrorMessages,
-    additionalErrors: nestedErrorMessages.slice(1),
+    allErrors: nestedErrorMessages,
   };
 }

Then in parseRaw, derive the heading and additional errors from the single list:

-    const { error, heading, additionalErrors } = formatValidationErrors(validator, content);
+    const { error, allErrors } = formatValidationErrors(validator, content);

     const headingMessage =
-      heading.length > 0
-        ? (heading[0].path ? `[${heading[0].path}] ` : "") + heading[0].message
+      allErrors.length > 0
+        ? (allErrors[0].path ? `[${allErrors[0].path}] ` : "") + allErrors[0].message
         : "Validation failed";
-    captureException(headingMessage, { extra: { additionalErrors, allErrors: heading } });
+    captureException(headingMessage, { extra: { additionalErrors: allErrors.slice(1), allErrors } });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/renderer/actions/local-sync/common-utils.ts` around lines 113 - 126,
formatValidationErrors currently returns misleadingly named properties: it
assigns the full nestedErrorMessages array to heading and a subset to
additionalErrors; rename and restructure to avoid redundancy by returning a
single errors list (e.g., allErrors or nestedErrorMessages) from
formatValidationErrors instead of heading/additionalErrors, then update parseRaw
to derive heading = errors[0] (or a computed summary) and additionalErrors =
errors.slice(1). Update references to the old heading/additionalErrors
properties accordingly (look for usages of formatValidationErrors, heading,
additionalErrors) and ensure types/signatures for formatValidationErrors reflect
the new single-list return value.

96-97: Simplify redundant path conditional.

The ternary on line 96 checks if nestedError.path is not undefined and not "", defaulting to "". This can be simplified.

♻️ Suggested simplification
-    const path = nestedError.path !== undefined && nestedError.path !== "" ? nestedError.path : "";
-    messages.push({ path, message: nestedError.message });
+    messages.push({ path: nestedError.path || "", message: nestedError.message });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/renderer/actions/local-sync/common-utils.ts` around lines 96 - 97,
Replace the redundant ternary that computes path with a concise
nullish-coalescing expression: set path to nestedError.path ?? "" (instead of
nestedError.path !== undefined && nestedError.path !== "" ? nestedError.path :
"") and then call messages.push({ path, message: nestedError.message }); this
keeps behavior but simplifies the conditional.

145-149: Use captureMessage or wrap in Error when reporting string messages to Sentry.

captureException is designed for Error objects. Passing a plain string (line 149) causes Sentry to generate a synthetic stack trace, which is less accurate and may group poorly in the Sentry dashboard. Either wrap the message in an Error or use captureMessage for string-based reports.

♻️ Option A: Wrap in Error
-    captureException(headingMessage, { extra: { additionalErrors, allErrors: heading } });
+    captureException(new Error(headingMessage), { extra: { additionalErrors, allErrors: heading } });
♻️ Option B: Use captureMessage (recommended)
-import { captureException } from "@sentry/browser";
+import { captureException, captureMessage } from "@sentry/browser";
-    captureException(headingMessage, { extra: { additionalErrors, allErrors: heading } });
+    captureMessage(headingMessage, { level: "error", extra: { additionalErrors, allErrors: heading } });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/renderer/actions/local-sync/common-utils.ts` around lines 145 - 149, The
current code builds a string headingMessage and passes it to
Sentry.captureException (headingMessage), which creates a synthetic stack;
instead either call Sentry.captureMessage(headingMessage, { level: "error",
extra: { additionalErrors, allErrors: heading } }) or wrap the string in an
Error before calling captureException (e.g., captureException(new
Error(headingMessage), { extra: { additionalErrors, allErrors: heading } }));
update the call site where headingMessage is used and ensure the same extra
payload (additionalErrors, allErrors: heading) is preserved.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/renderer/actions/local-sync/common-utils.ts`:
- Around line 113-126: formatValidationErrors currently returns misleadingly
named properties: it assigns the full nestedErrorMessages array to heading and a
subset to additionalErrors; rename and restructure to avoid redundancy by
returning a single errors list (e.g., allErrors or nestedErrorMessages) from
formatValidationErrors instead of heading/additionalErrors, then update parseRaw
to derive heading = errors[0] (or a computed summary) and additionalErrors =
errors.slice(1). Update references to the old heading/additionalErrors
properties accordingly (look for usages of formatValidationErrors, heading,
additionalErrors) and ensure types/signatures for formatValidationErrors reflect
the new single-list return value.
- Around line 96-97: Replace the redundant ternary that computes path with a
concise nullish-coalescing expression: set path to nestedError.path ?? ""
(instead of nestedError.path !== undefined && nestedError.path !== "" ?
nestedError.path : "") and then call messages.push({ path, message:
nestedError.message }); this keeps behavior but simplifies the conditional.
- Around line 145-149: The current code builds a string headingMessage and
passes it to Sentry.captureException (headingMessage), which creates a synthetic
stack; instead either call Sentry.captureMessage(headingMessage, { level:
"error", extra: { additionalErrors, allErrors: heading } }) or wrap the string
in an Error before calling captureException (e.g., captureException(new
Error(headingMessage), { extra: { additionalErrors, allErrors: heading } }));
update the call site where headingMessage is used and ensure the same extra
payload (additionalErrors, allErrors: heading) is preserved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant