Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for zod error #1146

Merged
merged 3 commits into from
Jan 3, 2025
Merged

Conversation

himanshu-dixit
Copy link
Collaborator

@himanshu-dixit himanshu-dixit commented Jan 3, 2025

🔍 Review Summary

Release Note

Purpose

  • Refine error handling in the SDK by implementing Zod error formatting.

Changes

Enhancement

  • Integrated Zod error formatting for improved error handling within the SDK, enhancing test coverage with a new error structure.
  • Revamped formatter.ts to format and display validation errors for BAD_REQUEST errors, providing clearer error descriptions for debugging and request validation.

Impact

  • Boosts error management in the SDK, aiding in debugging and creating better test cases, while enhancing the overall user experience with more comprehensible error messages.
Original Description

[!IMPORTANT]
Adds Zod error formatting for BAD_REQUEST errors in formatter.ts and updates tests in index.spec.ts.

  • Behavior:
    • Adds Zod error formatting in getAPIErrorDetails() in formatter.ts for BAD_REQUEST errors.
    • Formats validation errors as JSON strings in error descriptions.
  • Tests:
    • Updates test case in index.spec.ts to check for validation error descriptions containing JSON strings.

This description was created by Ellipsis for 6c60dd0. It will automatically update as commits are pushed.


Copy link

vercel bot commented Jan 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
composio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 3, 2025 7:07am

Copy link

Walkthrough

This update improves the SDK's error handling by integrating Zod error formatting. It enhances the index.spec.ts file to include validation errors, boosting test coverage. Additionally, formatter.ts is updated to format and display these errors, offering clearer error messages and aiding in debugging and request validation.

Changes

File(s) Summary
js/src/sdk/index.spec.ts Enhanced error structure to include validation errors, improving test coverage for error handling.
js/src/sdk/utils/errors/src/formatter.ts Added logic to format and display validation errors for BAD_REQUEST errors, providing clearer error descriptions and potential fixes.

🔗 Related PRs

Entelligence.ai can learn from your feedback. Simply add 👍 / 👎 emojis to teach it your preferences. More shortcuts below

Emoji Descriptions:

  • ⚠️ Potential Issue - May require further investigation.
  • 🔒 Security Vulnerability - Fix to ensure system safety.
  • 💻 Code Improvement - Suggestions to enhance code quality.
  • 🔨 Refactor Suggestion - Recommendations for restructuring code.
  • ℹ️ Others - General comments and information.

Interact with the Bot:

  • Send a message or request using the format:
    @bot + *your message*
Example: @bot Can you suggest improvements for this code?
  • Help the Bot learn by providing feedback on its responses.
    @bot + *feedback*
Example: @bot Do not comment on `save_auth` function !

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Reviewed everything up to 6262c9f in 35 seconds

More details
  • Looked at 69 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. js/src/sdk/utils/errors/src/formatter.ts:61
  • Draft comment:
    Consider providing a default value for validationErrors to avoid JSON.stringify on undefined.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    If validationErrors is undefined, JSON.stringify(undefined) returns 'undefined' as a string, which isn't necessarily wrong in this error handling context. The formattedErrors string will still work fine in the template literal. While providing a default value could be cleaner, this isn't causing any bugs or serious issues.
    The comment points out a real code style improvement opportunity. JSON.stringify(undefined) is a bit sloppy even if it technically works.
    However, this is an error handling utility where the exact format of the error message is not critical. The current code works fine and the suggested change would be purely cosmetic.
    While technically correct, this comment suggests a minor code style improvement that doesn't materially impact functionality. Following our rules about only keeping strongly necessary comments, we should remove it.

Workflow ID: wflow_PaI4aUSywrYC4J0f


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@@ -53,13 +54,25 @@ export const getAPIErrorDetails = (
}

switch (errorCode) {
case COMPOSIO_SDK_ERROR_CODES.BACKEND.BAD_REQUEST:
const validationErrors = axiosError.response?.data?.errors;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider adding type validation for the validation errors to ensure type safety:

const isValidationError = (errors: unknown): errors is Record<string, unknown>[] | Record<string, unknown> => {
  return errors !== null && typeof errors === 'object';
};

const validationErrors = axiosError.response?.data?.errors;
if (validationErrors && isValidationError(validationErrors)) {
  // process the errors
}

This would help prevent runtime errors if the error structure is unexpected.

Copy link

github-actions bot commented Jan 3, 2025

This comment was generated by github-actions[bot]!

JS SDK Coverage Report

📊 Coverage report for JS SDK can be found at the following URL:
https://pub-92e668239ab84bfd80ee07d61e9d2f40.r2.dev/coverage-12594094323/coverage/index.html

📁 Test report folder can be found at the following URL:
https://pub-92e668239ab84bfd80ee07d61e9d2f40.r2.dev/html-report-12594094323/html-report/report.html

@shreysingla11
Copy link
Collaborator

Code Review Summary

Overall Assessment

The changes to add Zod error support are well-structured and maintain consistency with the existing error handling system. The implementation properly handles both array and single object validation error formats.

Strengths

✅ Good error handling structure with detailed error information
✅ Maintains backward compatibility
✅ Test coverage is appropriate for the new functionality
✅ Clear separation of concerns in error formatting

Suggestions for Improvement

  1. Add type safety checks for validation errors
  2. Extract error formatting logic into a separate function
  3. Enhance documentation with JSDoc comments
  4. Consider adding more test cases for different validation error scenarios

Code Quality Rating: 8/10

The implementation is solid with good error handling patterns, but could benefit from the suggested improvements for better maintainability and type safety.

The PR is ready to merge after addressing the suggested improvements.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on c1fd196 in 23 seconds

More details
  • Looked at 54 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. js/src/sdk/index.spec.ts:61
  • Draft comment:
    The test case still uses 'errors' instead of 'details'. Update the expected object to use 'details' to match the changes in the formatter.ts file.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.

Workflow ID: wflow_WN4ZzhMloAt6GukN


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on 6c60dd0 in 10 seconds

More details
  • Looked at 15 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. js/src/sdk/index.spec.ts:83
  • Draft comment:
    Ensure that the error description is correctly formatted as a JSON string, as intended by the Zod error formatting enhancement. Consider adding assertions to verify the JSON structure and content.
  • Reason this comment was not posted:
    Comment did not seem useful.

Workflow ID: wflow_M1w6svVwCrltpMp6


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@himanshu-dixit himanshu-dixit merged commit 79e7b87 into master Jan 3, 2025
15 checks passed
@himanshu-dixit himanshu-dixit deleted the ft-add-support-for-zod-error branch January 3, 2025 11:37
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.

3 participants