PromucFlow_constructor/app/server/appsmith-plugins/postgresPlugin
Anna Hariprasad 1cf452fafa
feat: Improved-error-messages-for-postgres-connection (#35167)
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.

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 -->
2024-09-09 15:22:59 +01:00
..
src feat: Improved-error-messages-for-postgres-connection (#35167) 2024-09-09 15:22:59 +01:00
pom.xml chore: Introduce changes to minimize git footprint (#32595) 2024-04-16 21:34:24 +05:30