From cad2d1ded4b59378608e46f0a0598caf79926773 Mon Sep 17 00:00:00 2001
From: KushnirykOleh <kushnirykoleh@gmail.com>
Date: Fri, 31 Mar 2023 18:05:46 +0300
Subject: [PATCH] fixed error message, encoded username

---
 .../ext/mongodb/database/MongoConnection.java  | 18 +++++++++---------
 .../nosql/executor/NoSqlExecutor.java          | 11 +++++++----
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/src/main/java/liquibase/ext/mongodb/database/MongoConnection.java b/src/main/java/liquibase/ext/mongodb/database/MongoConnection.java
index 123c2633..bf9ece29 100644
--- a/src/main/java/liquibase/ext/mongodb/database/MongoConnection.java
+++ b/src/main/java/liquibase/ext/mongodb/database/MongoConnection.java
@@ -123,15 +123,8 @@ private String injectCredentials(final String url, final Properties driverProper
 
         if (nonNull(driverProperties)) {
 
-            final Optional<String> user = Optional.ofNullable(StringUtil.trimToNull(driverProperties.getProperty("user")));
-            final Optional<String> password = Optional.ofNullable(StringUtil.trimToNull(driverProperties.getProperty("password")))
-                    .map(s -> {
-                        try {
-                            return URLEncoder.encode(s, "UTF-8");
-                        } catch (UnsupportedEncodingException e) {
-                            throw new RuntimeException(e);
-                        }
-                    });
+            final Optional<String> user = Optional.ofNullable(StringUtil.trimToNull(driverProperties.getProperty("user"))).map(MongoConnection::encode);
+            final Optional<String> password = Optional.ofNullable(StringUtil.trimToNull(driverProperties.getProperty("password"))).map(MongoConnection::encode);
 
             if (user.isPresent()) {
                 // injects credentials
@@ -145,6 +138,13 @@ private String injectCredentials(final String url, final Properties driverProper
         return url;
     }
 
+    private static String encode(String s) {
+        try {
+            return URLEncoder.encode(s, "UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException(e);
+        }
+    }
 
     @Override
     public void close() throws DatabaseException {
diff --git a/src/main/java/liquibase/nosql/executor/NoSqlExecutor.java b/src/main/java/liquibase/nosql/executor/NoSqlExecutor.java
index 3fca7f36..0c6b329a 100644
--- a/src/main/java/liquibase/nosql/executor/NoSqlExecutor.java
+++ b/src/main/java/liquibase/nosql/executor/NoSqlExecutor.java
@@ -191,10 +191,13 @@ public void execute(final SqlStatement sql, final List<SqlVisitor> sqlVisitors)
         } else if (sql instanceof UpdateStatement) {
             execute((UpdateStatement) sql);
         } else {
-            //TODO DAT-14066 fix error message
-            throw new DatabaseException("liquibase-mongodb extension cannot execute " + sql.getClass().getSimpleName() +
-                    ". Please check your classpath, changeType name, other changeSet attributes like 'runWith' " +
-                    "to make sure you have appropriate handler for this change.");
+            throw new DatabaseException("liquibase-mongodb extension cannot execute changeset \n" +
+                    "Unknown type: " + sql.getClass().getName() +
+                    "\nPlease check the following common causes:\n" +
+                    "- Verify change set definitions for common error such as: changeType name, changeSet attributes spelling " +
+                    "(such as runWith,  context, etc.), and punctuation.\n" +
+                    "- Verify that changesets have all the required changeset attributes and do not have invalid attributes for the designated change type.\n" +
+                    "- Double-check to make sure your basic setup includes all needed extensions in your Java classpath");
         }
     }