dbml icon indicating copy to clipboard operation
dbml copied to clipboard

fix: define a common error format

Open H-DNA opened this issue 1 year ago • 2 comments

Summary

  • Define a common error interface.
  • Make Parser throw a consistent error class.
  • Add a tsconfig.json file to perform some superficial typechecking, e.g ensuring that an error class conforms to the defined error interface.
  • BREAKING CHANGE: dbml/cli always show errors on a new line.

Effects: Silent errors (thrown by normalize) have been caught: image

Issue

(issue link here)

Lasting Changes (Technical)

  • types/index,d.ts
  • types/parse/error.d.ts
  • src/parse/error.js for the common CompilerError class.
  • init tsconfig.json
  • Add some JSDoc to ensure an error class conforms to the error interface.
  • dbml-cli package where errors are handled.

Checklist

Please check directly on the box once each of these are done

  • [ ] Documentation (if necessary)
  • [ ] Tests (integration test/unit test)
  • [ ] Integration Tests Passed
  • [ ] Code Review

Summary by CodeRabbit

  • New Features
    • Introduced improved error handling and diagnostics for syntax errors in database schemas.
  • Bug Fixes
    • Enhanced readability of error messages related to duplicate endpoints in database schemas.
  • Refactor
    • Updated error handling mechanisms across various modules for better clarity and maintenance.
  • Documentation
    • Added TypeScript type definitions for compiler diagnostics and error handling.

H-DNA avatar Mar 20 '24 20:03 H-DNA

@NQPhuc Maybe we can delete the tsconfig.json (redundant) + the readonly [key: string]: any; (confusion and redundant too) in CompilerDiagnostic altogether.

H-DNA avatar Mar 25 '24 12:03 H-DNA

Walkthrough

The recent updates focus on enhancing error handling across the DBML project. Improvements include better formatting of error messages for clarity, the introduction of the CompilerError class to manage compiler diagnostics efficiently, and updates in error mapping and logging mechanisms. These changes aim to provide clearer insights into issues encountered during the database schema parsing and compilation processes, making debugging and error resolution more intuitive for developers.

Changes

Files Change Summary
.../syntax-error-duplicate-endpoints/mssql/stdout.txt
.../syntax-error-duplicate-endpoints/mysql/stdout.txt
Improved readability of error messages related to syntax errors with duplicate endpoints.
.../cli/export.js
.../cli/import.js
Enhanced error handling by mapping error.diags to SyntaxError instances for better logging.
.../cli/utils.js
.../core/src/index.js
.../core/src/model_structure/element.js
.../core/src/parse/Parser.js
.../core/src/parse/error.js
Integrated CompilerError for advanced error management and diagnostics.
.../types/index.d.ts
.../types/parse/error.d.ts
Added TypeScript definitions for compiler diagnostics and error handling.

🐇✨
In the realm of code where the DBML trees grow,
A rabbit hopped in, with updates in tow.
"Fear not," it said, "for errors we tame,
With CompilerError's might and a clearer aim."
Now debug with ease, as clarity reigns,
For in the world of DBML, improvement sustains.
🌟📚


Recent Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between bc23f17e6276724cfc1e8efacd56b59c03319d2b and 34e78a5504bc0f26e4604e3c953a7e749a2d8e60.
Files selected for processing (1)
  • packages/dbml-core/types/parse/error.d.ts (1 hunks)
Additional comments not posted (5)
packages/dbml-core/types/parse/error.d.ts (5)

1-4: Consider documenting the WarningLevel type.

Adding comments to explain the purpose and usage of each warning level (error, warning, info) can improve code readability and maintainability.


6-6: The ErrorCode type is well-defined.

This simple type definition for error codes as numbers is clear and straightforward.


8-11: The EditorPosition interface is clearly defined.

This interface provides a clear structure for representing positions within the editor, which is essential for error reporting.


13-24: Ensure consistency in optional properties within CompilerDiagnostic.

While the CompilerDiagnostic interface is well-structured, consider the consistency of optional properties. For instance, filepath and type are optional, but code is also optional. Ensure that this aligns with the intended usage scenarios of diagnostics.


26-28: The CompilerError interface encapsulates diagnostics effectively.

This interface correctly aggregates multiple CompilerDiagnostic instances, aligning with the goal of standardized error handling.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Mar 26 '24 07:03 coderabbitai[bot]