feat: Improved-error-messages-for-postgres-connection
Hi @appsmithorg/contributor-support, @rohan-arthur, @nidhi-nair
Fixes #19723
What’s in this PR:
- 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.
- In PostgresErrorMessages
- Added two constant value for Missing port and invalid host and port.
- In PostgresPluginTest
- Added a test case to validate the missing port error message.
Screenshots :
- 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
- If host address or port is wrong, there is no reference of that in the error message. - Fixed
- There is no error message when the port number is left empty. - Fixed
Test cases :
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.
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?
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
@coderabbitaiin 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
@coderabbitaiin 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 pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere 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.
Hi @nidhi-nair, Could you review this pr or assign anyone to review this pr.
This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.
Hi @rohan-arthur, @nidhi-nair Could you please review this pr.
Hi @nidhi-nair, Can you assign anyone to review this pr.
This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.
Commenting to keep the PR alive
@AnnaHariprasad5123 can you resolve merge conflicts here
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.
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.
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 :
- cypress/e2e/Regression/ClientSide/MobileResponsiveTests/ConversionFlow_Generated_App_spec.ts
- cypress/e2e/Regression/ClientSide/OneClickBinding/PropertyControl_spec.ts
- cypress/e2e/Regression/ClientSide/OtherUIFeatures/EntityBottomBar_spec.ts
- cypress/e2e/Smoke/GenerateCRUD/Generate_Crud_New_Page_spec.ts
Hi @NilanshBansal, Could you check this pr.
/build-deploy-preview skip-tests=true
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: .
Deploy-Preview-URL: https://ce-35167.dp.appsmith.com
@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
@AnnaHariprasad5123 Please check the error messaging it has a full stop and a comma together. Comma should not be present
Hi @NilanshBansal Good morning, Could you check once now.
@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.
@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:applyand then commit.
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.
@AnnaHariprasad5123 can you check your IDE formatter rules.
These are the config from my IDE
@NilanshBansal , Same config from my side already.
Hi @NilanshBansal, Done mvn spotless:apply. Postgres plugin resets indentations. Could you check once now.
/build-deploy-preview skip-tests=true recreate=true
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.
Deploy-Preview-URL: https://ce-35167.dp.appsmith.com
@AnnaHariprasad5123 can you please also add a unit test for this scenario. You can take reference from the coderabbit suggestion here https://github.com/appsmithorg/appsmith/pull/36053#discussion_r1749803876
Hi @NilanshBansal, createConnectionPool method is private method. Is it good to write test case for private methods?
Hi @NilanshBansal, createConnectionPool method is private method. Is it good to write test case for private methods?
@AnnaHariprasad5123 thanks for highlighting we can skip it in this scenario.

