8000 fix: throw error if invalid operator used in xcCondition by DarkPhoenix2704 · Pull Request #8568 · nocodb/nocodb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: throw error if invalid operator used in xcCondition #8568

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

Merged
merged 5 commits into from
May 30, 2024

Conversation

DarkPhoenix2704
Copy link
Member

Change Summary

Provide summary of changes with issue number if any.

Change type

  • feat: (new feature for the user, not a new feature for build script)
  • fix: (bug fix for the user, not a fix to a build script)
  • docs: (changes to the documentation)
  • style: (formatting, missing semi colons, etc; no production code change)
  • refactor: (refactoring production code, eg. renaming a variable)
  • test: (adding missing tests, refactoring tests; no production code change)
  • chore: (updating grunt tasks etc; no production code change)

Test/ Verification

Provide summary of changes.

Additional information / screenshots (optional)

Anything for maintainers to be made aware of

@DarkPhoenix2704 DarkPhoenix2704 requested a review from pranavxc May 24, 2024 06:41
@DarkPhoenix2704 DarkPhoenix2704 self-assigned this May 24, 2024
Copy link
Contributor
coderabbitai bot commented May 24, 2024
Walkthrough

Walkthrough

The recent changes to the CustomKnex.ts file in the nocodb package involve enhancing error handling within the parseCondition function. Specifically, a throw statement has been added to manage cases where an invalid operator is encountered during condition parsing. This improvement ensures that invalid operators are promptly flagged, aiding in debugging and maintaining code robustness.

Changes

File Path Change Summary
packages/nocodb/src/db/CustomKnex.ts Added a throw statement in the parseCondition function to handle invalid operator cases within a switch statement.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant Client
    participant CustomKnex

    Client->>CustomKnex: call parseCondition(obj, columnAliases, qb, pKey?)
    CustomKnex->>CustomKnex: Evaluate condition
    alt Valid operator
        CustomKnex->>Client: Return parsed condition
    else Invalid operator
        CustomKnex->>Client: Throw error
    end
Loading

Tip

Early Access Features
  • gpt-4o model for chat

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to full the review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @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.

Copy link
Contributor
@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.

Actionable comments posted: 1

Outside diff range and nitpick comments (6)
packages/nocodb/src/db/CustomKnex.ts (6)

Line range hint 72-72: Replace != with !== for strict comparison.

- if (str && str != '~not')
+ if (str && str !== '~not')

Using strict equality (!==) avoids type coercion and should be used instead of loose equality (!=) to ensure more predictable code behavior.

Also applies to: 83-83, 98-98, 227-227, 262-262


Line range hint 134-491: Consider replacing forEach with for...of.

Using for...of provides better readability and is generally more performant in scenarios where the loop might be broken out of, which is not possible with forEach.


Line range hint 489-489: Use template literals instead of string concatenation.

- alias: `${this._tn[relation.tn] ? this._tn[relation.tn] + '___' : ''}${relation.tn}`,
+ alias: `${this._tn[relation.tn] ? `${this._tn[relation.tn]}___` : ''}${relation.tn}`,

Template literals provide clearer syntax and improved readability, especially when dealing with complex expressions.


Line range hint 223-223: Remove or refactor unreachable code.

Unreachable code can lead to confusion and clutter in the codebase. It's important to either remove it or refactor the logic to make the code paths reachable.

Also applies to: 258-258, 295-295, 352-352, 414-414, 484-484


Line range hint 118-494: Consider converting function expressions to arrow functions.

Arrow functions provide a cleaner and more concise syntax and lexically bind the this value, which is often desirable in modular JavaScript code.


Line range hint 173-173: Specify a more precise type instead of any.

Using any type can lead to potential runtime errors and makes the code less maintainable and understandable. Where possible, replace any with a more specific type to enhance type safety and clarity.

Also applies to: 499-499, 541-541, 567-567

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 74658d7 and a34cfac.
Files selected for processing (1)
  • packages/nocodb/src/db/CustomKnex.ts (1 hunks)
Additional Context Used
Biome (20)
packages/nocodb/src/db/CustomKnex.ts (20)

72-72: Use !== instead of !=.
!= is only allowed when comparing against null


81-83: The assignment should not be in an expression.


83-83: Use !== instead of !=.
!= is only allowed when comparing against null


98-98: Use !== instead of !=.
!= is only allowed when comparing against null


134-491: Prefer for...of instead of forEach.


173-173: Unexpected any. Specify a different type.


227-227: Use !== instead of !=.
!= is only allowed when comparing against null


262-262: Use !== instead of !=.
!= is only allowed when comparing against null


470-470: Use === instead of ==.
== is only allowed when comparing against null


489-489: Template literals are preferred over string concatenation.


223-223: This code is unreachable


258-258: This code is unreachable


295-295: This code is unreachable


352-352: This code is unreachable


414-414: This code is unreachable


484-484: This code is unreachable


118-494: This function expression can be turned into an arrow function.


499-499: Unexpected any. Specify a different type.


541-541: Unexpected any. Specify a different type.


567-567: Unexpected any. Specify a different type.

@o1lab o1lab force-pushed the nc-fix/invalid-error branch from a34cfac to 518801d Compare May 24, 2024 06:56
Copy link
Contributor
@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.

Actionable comments posted: 1

Outside diff range and nitpick comments (2)
packages/nocodb/src/db/CustomKnex.ts (2)

Line range hint 72-72: Replace != with !== and == with === to avoid type coercion issues.

- if (openIndex == -1) openIndex = str.indexOf('(~');
+ if (openIndex === -1) openIndex = str.indexOf('(~');

- if (closingIndex == -1)
+ if (closingIndex === -1)

- if (operandStartIndex != -1)
+ if (operandStartIndex !== -1)

- if (matches[3] != 'null')
+ if (matches[3] !== 'null')

- if (matches[4] != 'null')
+ if (matc
8000
hes[4] !== 'null')

- if (matches[3] == 'like' && clientType === 'pg') {
+ if (matches[3] === 'like' && clientType === 'pg') {

Also applies to: 83-83, 98-98, 227-227, 262-262, 470-470


Line range hint 134-491: Consider refactoring forEach loops to for...of loops for better performance and readability.

- conditions.forEach((condition) => {
+ for (const condition of conditions) {
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between a34cfac and 518801d.
Files selected for processing (1)
  • packages/nocodb/src/db/CustomKnex.ts (1 hunks)
Additional Context Used
Biome (20)
packages/nocodb/src/db/CustomKnex.ts (20)

72-72: Use !== instead of !=.
!= is only allowed when comparing against null


81-83: The assignment should not be in an expression.


83-83: Use !== instead of !=.
!= is only allowed when comparing against null


98-98: Use !== instead of !=.
!= is only allowed when comparing against null


134-491: Prefer for...of instead of forEach.


173-173: Unexpected any. Specify a different type.


227-227: Use !== instead of !=.
!= is only allowed when comparing against null


262-262: Use !== instead of !=.
!= is only allowed when comparing against null


470-470: Use === instead of ==.
== is only allowed when comparing against null


489-489: Template literals are preferred over string concatenation.


223-223: This code is unreachable


258-258: This code is unreachable


295-295: This code is unreachable


352-352: This code is unreachable


414-414: This code is unreachable


484-484: This code is unreachable


118-494: This function expression can be turned into an arrow function.


499-499: Unexpected any. Specify a different type.


541-541: Unexpected any. Specify a different type.


567-567: Unexpected any. Specify a different type.

Copy link
Contributor
github-actions bot commented May 24, 2024

Uffizzi Preview deployment-52215 was deleted.

@o1lab o1lab force-pushed the nc-fix/invalid-error branch 2 times, most recently from c627141 to a6e477b Compare May 24, 2024 14:04
@o1lab o1lab force-pushed the nc-fix/invalid-error branch from a6e477b to 2e8f65b Compare May 28, 2024 04:49
Copy link
Contributor
@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.

Actionable comments posted: 0

Outside diff range and nitpick comments (6)
packages/nocodb/src/db/CustomKnex.ts (6)

Line range hint 73-73: Replace != with !== to ensure strict type comparison.

- if (openIndex == -1) openIndex = str.indexOf('(~');
+ if (openIndex === -1) openIndex = str.indexOf('(~');

- if (closingIndex == -1)
+ if (closingIndex === -1)

- if (operandStartIndex != -1)
+ if (operandStartIndex !== -1)

- if (matches[1] != '')
+ if (matches[1] !== '')

- if (matches[4] != 'null')
+ if (matches[4] !== 'null')

Also applies to: 84-84, 99-99, 228-228, 263-263


Line range hint 135-492: Consider using for...of instead of forEach for better performance and readability in modern JavaScript.

- conditions.forEach((condition) => {
+ for (const condition of conditions) {

Line range hint 471-471: Use === for strict equality comparison to avoid unexpected type coercion.

- if (matches[3] == 'like' && clientType === 'pg') {
+ if (matches[3] === 'like' && clientType === 'pg') {

Line range hint 490-490: Use template literals for string concatenation to improve readability and maintainability.

- alias: `${
-   this._tn[relation.tn] ? this._tn[relation.tn] + '___' : ''
- }${relation.tn}`,
+ alias: `${this._tn[relation.tn] ? `${this._tn[relation.tn]}___` : ''}${relation.tn}`,

Line range hint 174-174: Specify a more explicit type instead of any to enhance type safety and code clarity.

- const matches: any[] = condition.match(
+ const matches: Array<string | null> = condition.match(

Also applies to: 546-546, 574-574, 584-584


Line range hint 119-495: Convert this function expression to an arrow function for better readability and to maintain the lexical this.

- conditions.forEach((condition) => {
+ conditions.forEach((condition) => {
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 518801d and 2e8f65b.
Files selected for processing (1)
  • packages/nocodb/src/db/CustomKnex.ts (2 hunks)
Additional Context Used
Biome (20)
packages/nocodb/src/db/CustomKnex.ts (20)

73-73: Use !== instead of !=.
!= is only allowed when comparing against null


82-84: The assignment should not be in an expression.


84-84: Use !== instead of !=.
!= is only allowed when comparing against null


99-99: Use !== instead of !=.
!= is only allowed when comparing against null


135-492: Prefer for...of instead of forEach.


174-174: Unexpected any. Specify a different type.


228-228: Use !== instead of !=.
!= is only allowed when comparing against null


263-263: Use !== instead of !=.
!= is only allowed when comparing against null


471-471: Use === instead of ==.
== is only allowed when comparing against null


490-490: Template literals are preferred over string concatenation.


224-224: This code is unreachable


259-259: This code is unreachable


296-296: This code is unreachable


353-353: This code is unreachable


415-415: This code is unreachable


485-485: This code is unreachable


119-495: This function expression can be turned into an arrow function.


546-546: Unexpected any. Specify a different type.


574-574: Unexpected any. Specify a different type.


584-584: Unexpected any. Specify a different type.

Additional comments not posted (1)
packages/nocodb/src/db/CustomKnex.ts (1)

695-699: The error handling for invalid operators is a crucial improvement for robustness. Consider providing more context in the error message to aid debugging.

- throw new Error(`Found invalid conditional operator "${key}" in expression`);
+ throw new Error(`Found invalid conditional operator "${key}" in expression. Please check the condition object for correct syntax.`);

@dstala
Copy link
Member
dstala commented May 30, 2024

merging sans approval from @pranavxc as the corresponding PR was approved in hub already

@dstala dstala merged commit 25db00b into develop May 30, 2024
23 checks passed
@dstala dstala deleted the nc-fix/invalid-error branch May 30, 2024 10:44
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.

2 participants
0