Skip to content

Commit

Permalink
chore: shadow PR for external contribution #ce-35167 (#36053)
Browse files Browse the repository at this point in the history
## 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 <[email protected]>
  • Loading branch information
NilanshBansal and AnnaHariprasad5123 authored Sep 9, 2024
1 parent aac30b6 commit b782bde
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/client/src/sagas/DatasourcesSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ function* testDatasourceSaga(actionPayload: ReduxAction<Datasource>) {
id: datasource.id,
environmentId: currentEnvironment,
show: true,
error: { message: responseData.invalids.join(", ") },
error: { message: responseData.invalids.join("\n") },
},
});
AppsmithConsole.error({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import org.pf4j.Extension;
import org.pf4j.PluginWrapper;
import org.postgresql.util.PGobject;
import org.postgresql.util.PSQLException;
import org.postgresql.util.PSQLState;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -1347,10 +1349,21 @@ private static HikariDataSource createConnectionPool(
try {
datasource = new HikariDataSource(config);
} catch (PoolInitializationException e) {
Throwable cause = e.getCause();
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,
e.getMessage());
cause != null ? cause.getMessage() : e.getMessage());
}

return datasource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ public class PostgresErrorMessages extends BasePluginErrorMessages {
public static final String DS_MISSING_PASSWORD_ERROR_MSG = "Missing password for authentication.";

public static final String DS_MISSING_DATABASE_NAME_ERROR_MSG = "Missing database name.";

public static final String DS_INVALID_HOSTNAME_AND_PORT_MSG = "Please check the host and port.";
}

0 comments on commit b782bde

Please sign in to comment.