Skip to content

feat: Improved-error-messages-for-postgres-connection#35167

Merged
nerbos merged 7 commits intoappsmithorg:releasefrom
AnnaHariprasad5123:Issue-#19723/feat-postgres-conn-error-msg-improvements
Sep 9, 2024
Merged

feat: Improved-error-messages-for-postgres-connection#35167
nerbos merged 7 commits intoappsmithorg:releasefrom
AnnaHariprasad5123:Issue-#19723/feat-postgres-conn-error-msg-improvements

Conversation

@AnnaHariprasad5123
Copy link
Contributor

@AnnaHariprasad5123 AnnaHariprasad5123 commented Jul 25, 2024

Hi @appsmithorg/contributor-support, @rohan-arthur, @nidhi-nair

Fixes #19723

What’s in this PR:

  1. In Postgres Plugin:
  • Added two imports: PSQLException and PSQLState to identify the type of exception and state of error.
  • Added a condition to validate the empty port field.
  • Removed the default port when the port is empty.
  • Removed “Failed to initialize pool:” term in the error message.
  1. In PostgresErrorMessages
  • Added two constant value for Missing port and invalid host and port.
  1. In PostgresPluginTest
  • Added a test case to validate the missing port error message.

Screenshots :

  1. If any of the field like host address, port, DB name etc is wrong - There is a term in the error message along with the error message in the toast "Failed to initialize pool: ". This is not required. - Fixed
    image
  2. If host address or port is wrong, there is no reference of that in the error message. - Fixed
    image
  3. There is no error message when the port number is left empty. - Fixed
    image

Test cases :
image

Why I didn’t provide test cases for invalid host and port :

Those errors are triggered by the createConnectionPool method, which is private, so we can’t access it in the test file.

Summary by CodeRabbit

  • New Features

    • Improved validation for PostgreSQL datasource configurations, ensuring that a port is specified.
    • Enhanced error messaging for connection issues related to missing or invalid port and hostname.
  • Bug Fixes

    • Refined error handling during connection pool initialization for clearer feedback on specific connection issues.
  • Tests

    • Added a test to validate behavior when the datasource configuration has an empty port, improving coverage for validation logic.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 25, 2024

Walkthrough

The updates enhance the PostgreSQL plugin by improving validation and error messaging for datasource configurations. Key modifications include checks for missing ports, refined JDBC URL construction, and enhanced error handling during connection pool initialization. These changes ensure clearer feedback for users, allowing for better troubleshooting of connectivity issues.

Changes

File Change Summary
.../PostgresPlugin.java Added validation for empty ports, refined connection pool logic, and improved error handling for connection exceptions.
.../PostgresErrorMessages.java Introduced new error message constants for missing ports and invalid host/port configurations to enhance user guidance.
.../PostgresPluginTest.java Added a new test to validate behavior when the datasource configuration has an empty port, improving test coverage.

Assessment against linked issues

Objective Addressed Explanation
Error message improvements for wrong host/port and empty port (19723)
Clearer user feedback for connection issues (19723)
Removal of unnecessary error message terms (19723) The term "Failed to initialize pool:" is still present in error messages.

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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using 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 do a full 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 configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@AnnaHariprasad5123 AnnaHariprasad5123 changed the title feat:Improved-error-messages-for-postgres-connection feat: Improved-error-messages-for-postgres-connection Jul 25, 2024
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4839110 and f08932c.

Files selected for processing (3)
  • app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java (4 hunks)
  • app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/exceptions/PostgresErrorMessages.java (2 hunks)
  • app/server/appsmith-plugins/postgresPlugin/src/test/java/com/external/plugins/PostgresPluginTest.java (1 hunks)
Additional comments not posted (7)
app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/exceptions/PostgresErrorMessages.java (2)

40-40: LGTM!

The addition of DS_MISSING_PORT_ERROR_MSG improves error clarity when the port is missing.


53-53: LGTM!

The addition of DS_INVALID_HOSTNAME_AND_PORT_MSG improves error clarity when both the host and port need to be checked.

app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java (4)

46-46: LGTM!

The import of PSQLException is necessary for handling specific SQL exceptions.


47-47: LGTM!

The import of PSQLState is necessary for handling specific SQL state codes.


673-675: LGTM!

The added validation check for missing port ensures comprehensive error reporting and aligns with the PR objectives.


1268-1288: LGTM!

The enhanced error handling during connection pool initialization provides clearer feedback for users and aligns with the PR objectives.

app/server/appsmith-plugins/postgresPlugin/src/test/java/com/external/plugins/PostgresPluginTest.java (1)

359-365: LGTM! The new test case is well-structured and effective.

The test case correctly validates the scenario where the port is missing and ensures the appropriate error message is returned.

@AnnaHariprasad5123
Copy link
Contributor Author

Hi @nidhi-nair, Could you review this pr or assign anyone to review this pr.

@github-actions
Copy link

github-actions bot commented Aug 7, 2024

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Aug 7, 2024
@AnnaHariprasad5123
Copy link
Contributor Author

Hi @rohan-arthur, @nidhi-nair Could you please review this pr.

@nidhi-nair nidhi-nair requested a review from a team August 8, 2024 04:56
@github-actions github-actions bot removed the Stale label Aug 8, 2024
@NilanshBansal NilanshBansal added Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags. Community Contributor Meant to track issues that are assigned to external contributors labels Aug 10, 2024
@AnnaHariprasad5123
Copy link
Contributor Author

Hi @nidhi-nair, Can you assign anyone to review this pr.

@github-actions
Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@NilanshBansal
Copy link
Contributor

Commenting to keep the PR alive

@NilanshBansal
Copy link
Contributor

@AnnaHariprasad5123 can you resolve merge conflicts here

@AnnaHariprasad5123
Copy link
Contributor Author

Hi @NilanshBansal, Now we can't get "Missing Port" error. Because it will take default port value. If I remove default port there, users DB will not work which we face in my previous pr.

@NilanshBansal
Copy link
Contributor

Hi @NilanshBansal, Now we can't get "Missing Port" error. Because it will take default port value. If I remove default port there, users DB will not work which we face in my previous pr.

Yes, that is fine @AnnaHariprasad5123.

@AnnaHariprasad5123
Copy link
Contributor Author

Hi @NilanshBansal

Good morning, I removed the code related to Missing Port error that fixed the cypress tests. Remaining cypress tests are failed due to docker.internal url.

Screenshots :

  1. cypress/e2e/Regression/ClientSide/MobileResponsiveTests/ConversionFlow_Generated_App_spec.ts
    image
  2. cypress/e2e/Regression/ClientSide/OneClickBinding/PropertyControl_spec.ts
    image
  3. cypress/e2e/Regression/ClientSide/OtherUIFeatures/EntityBottomBar_spec.ts
    image
  4. cypress/e2e/Smoke/GenerateCRUD/Generate_Crud_New_Page_spec.ts
    image

@AnnaHariprasad5123
Copy link
Contributor Author

Hi @NilanshBansal, Could you check this pr.

Comment on lines +1334 to +1345
} else {
throw new AppsmithPluginException(
AppsmithPluginError.PLUGIN_DATASOURCE_ARGUMENT_ERROR,
PostgresErrorMessages.CONNECTION_POOL_CREATION_FAILED_ERROR_MSG,
cause.getMessage());
}
} else {
throw new AppsmithPluginException(
AppsmithPluginError.PLUGIN_DATASOURCE_ARGUMENT_ERROR,
PostgresErrorMessages.CONNECTION_POOL_CREATION_FAILED_ERROR_MSG,
cause != null ? cause.getMessage() : e.getMessage());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@AnnaHariprasad5123 can we avoid using these two else blocks to reduce code duplication as both of them return the same exception, can we just use the code structure as below.

if (cause instanceof PSQLException) {
    PSQLException psqlException = (PSQLException) cause;
    String sqlState = psqlException.getSQLState();
    
    if (PSQLState.CONNECTION_UNABLE_TO_CONNECT.getState().equals(sqlState)) {
        throw new AppsmithPluginException(
            AppsmithPluginError.PLUGIN_DATASOURCE_ARGUMENT_ERROR,
            PostgresErrorMessages.DS_INVALID_HOSTNAME_AND_PORT_MSG,
            psqlException.getMessage()
        );
    }
}

throw new AppsmithPluginException(
    AppsmithPluginError.PLUGIN_DATASOURCE_ARGUMENT_ERROR,
    PostgresErrorMessages.CONNECTION_POOL_CREATION_FAILED_ERROR_MSG,
    cause != null ? cause.getMessage() : e.getMessage()
);

@NilanshBansal
Copy link
Contributor

/build-deploy-preview skip-tests=true

@github-actions
Copy link

github-actions bot commented Sep 6, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10733008767.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 35167.
recreate: .

@github-actions
Copy link

github-actions bot commented Sep 6, 2024

Deploy-Preview-URL: https://ce-35167.dp.appsmith.com

@NilanshBansal
Copy link
Contributor

@AnnaHariprasad5123 can you resolve merge conflicts by taking the latest pull.
Also, there are a number of indentation changes in your last commit can you please check how these have appeared

@NilanshBansal
Copy link
Contributor

@AnnaHariprasad5123 Please check the error messaging it has a full stop and a comma together. Comma should not be present
SCR-20240906-h4g

@AnnaHariprasad5123
Copy link
Contributor Author

Hi @NilanshBansal Good morning, Could you check once now.

Comment on lines +926 to +937
responseData.invalids.forEach((message: string) => {
toast.show(message, {
kind: "error",
});
});
yield put({
type: ReduxActionErrorTypes.TEST_DATASOURCE_ERROR,
payload: {
show: false,
id: datasource.id,
environmentId: currentEnvironment,
show: true,
error: { message: responseData.invalids.join(", ") },
messages: messages,
Copy link
Contributor

Choose a reason for hiding this comment

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

@AnnaHariprasad5123 this change would create a different toast message for each message in the invalids array.
If you want to still do toast error but without the comma, that line can be changed to:
show: true, error: { message: responseData.invalids.join("\n") },

cc: @hetunandu @sneha122

@NilanshBansal
Copy link
Contributor

@AnnaHariprasad5123 can you also check why there are a number of indentation changes in your last commit. This makes it very difficult to review. Can you please remove the unnecessary indentation changes and run mvn spotless:apply and then commit.
image

@AnnaHariprasad5123
Copy link
Contributor Author

@AnnaHariprasad5123 can you also check why there are a number of indentation changes in your last commit. This makes it very difficult to review. Can you please remove the unnecessary indentation changes and run mvn spotless:apply and then commit. image

When I save a file, the code automatically changes its formatting. This makes the lines look indented, even if I delete the extra spaces after saving it got formatted. When I run the mvn spotless:apply check command, it fails because the code doesn't match the desired formatting rules.

@NilanshBansal
Copy link
Contributor

NilanshBansal commented Sep 9, 2024

@AnnaHariprasad5123 can you check your IDE formatter rules.
These are the config from my IDE
image

@AnnaHariprasad5123
Copy link
Contributor Author

AnnaHariprasad5123 commented Sep 9, 2024

@NilanshBansal , Same config from my side already.
image

@AnnaHariprasad5123
Copy link
Contributor Author

AnnaHariprasad5123 commented Sep 9, 2024

Hi @NilanshBansal, Done mvn spotless:apply. Postgres plugin resets indentations. Could you check once now.

image

@NilanshBansal NilanshBansal self-requested a review September 9, 2024 07:56
@NilanshBansal
Copy link
Contributor

/build-deploy-preview skip-tests=true recreate=true

@github-actions
Copy link

github-actions bot commented Sep 9, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10768967470.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 35167.
recreate: true.

@github-actions
Copy link

github-actions bot commented Sep 9, 2024

Deploy-Preview-URL: https://ce-35167.dp.appsmith.com

@NilanshBansal
Copy link
Contributor

@AnnaHariprasad5123 can you please also add a unit test for this scenario.
You can take reference from the coderabbit suggestion here
#36053 (comment)

@AnnaHariprasad5123
Copy link
Contributor Author

Hi @NilanshBansal, createConnectionPool method is private method. Is it good to write test case for private methods?
image

@NilanshBansal
Copy link
Contributor

Hi @NilanshBansal, createConnectionPool method is private method. Is it good to write test case for private methods? image

@AnnaHariprasad5123 thanks for highlighting we can skip it in this scenario.

nerbos pushed a commit that referenced this pull request Sep 9, 2024
## Description
- Shadow PR for #35167

Fixes #  

> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/test all

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10769007798>
> Commit: 3c97f02
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10769007798&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Mon, 09 Sep 2024 10:29:27 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit


- **New Features**
- Enhanced error handling for PostgreSQL connection issues with clearer
messages for missing ports and invalid hostnames.
- Improved readability of error messages in the application by
formatting them to display on separate lines.

- **Bug Fixes**
- Improved clarity in error reporting for connection pool creation
failures.

- **Tests**
- Introduced a test case to validate datasource configuration when the
port is not provided, ensuring robust validation checks.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: AnnaHariprasad5123 <hariprasad.anna@zemosolabs.com>
@nerbos nerbos merged commit 1cf452f into appsmithorg:release Sep 9, 2024
Shivam-z pushed a commit to Shivam-z/appsmith that referenced this pull request Sep 26, 2024
## Description
- Shadow PR for appsmithorg#35167

Fixes #  

> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/test all

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10769007798>
> Commit: 3c97f02
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10769007798&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Mon, 09 Sep 2024 10:29:27 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit


- **New Features**
- Enhanced error handling for PostgreSQL connection issues with clearer
messages for missing ports and invalid hostnames.
- Improved readability of error messages in the application by
formatting them to display on separate lines.

- **Bug Fixes**
- Improved clarity in error reporting for connection pool creation
failures.

- **Tests**
- Introduced a test case to validate datasource configuration when the
port is not provided, ensuring robust validation checks.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: AnnaHariprasad5123 <hariprasad.anna@zemosolabs.com>
Shivam-z pushed a commit to Shivam-z/appsmith that referenced this pull request Sep 26, 2024
)

Hi @appsmithorg/contributor-support, @rohan-arthur, @nidhi-nair 

Fixes appsmithorg#19723 

**What’s in this PR:**

1. In Postgres Plugin:

- Added two imports: PSQLException and PSQLState to identify the type of
exception and state of error.
- Added a condition to validate the empty port field.
- Removed the default port when the port is empty.
- Removed “Failed to initialize pool:” term in the error message.

2. In PostgresErrorMessages

- Added two constant value for Missing port and invalid host and port.

3. In PostgresPluginTest

- Added a test case to validate the missing port error message.

**Screenshots :**
1. If any of the field like host address, port, DB name etc is wrong -
There is a term in the error message along with the error message in the
toast "Failed to initialize pool: ". This is not required. - Fixed

![image](https://github.com/user-attachments/assets/a54ff455-7297-4356-bf81-656c1130977a)
2. If host address or port is wrong, there is no reference of that in
the error message. - Fixed

![image](https://github.com/user-attachments/assets/c48dabdc-9957-459a-9dde-d4b73960b9e2)
3. There is no error message when the port number is left empty. - Fixed

![image](https://github.com/user-attachments/assets/2c7967c8-b4e1-4bb2-a8e5-14e8022bca29)

**Test cases :**

![image](https://github.com/user-attachments/assets/329a7453-c1ba-4a85-b807-2cdf4569db3e)

**Why I didn’t provide test cases for invalid host and port :**

Those errors are triggered by the createConnectionPool method, which is
private, so we can’t access it in the test file.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Improved validation for PostgreSQL datasource configurations, ensuring
that a port is specified.
- Enhanced error messaging for connection issues related to missing or
invalid port and hostname.

- **Bug Fixes**
- Refined error handling during connection pool initialization for
clearer feedback on specific connection issues.

- **Tests**
- Added a test to validate behavior when the datasource configuration
has an empty port, improving coverage for validation logic.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community Contributor Meant to track issues that are assigned to external contributors Integrations Pod General Issues related to the Integrations Pod that don't fit into other tags.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Postgres error message improvements on connectivity

3 participants