Throws ConfigException when validation fails

This commit is contained in:
majialong 2025-10-05 11:59:18 +08:00
parent 2210830a8b
commit f22501b7bd
2 changed files with 9 additions and 8 deletions

View File

@ -16,6 +16,7 @@
*/ */
package org.apache.kafka.tools; package org.apache.kafka.tools;
import org.apache.kafka.common.config.ConfigException;
import org.apache.kafka.common.utils.Exit; import org.apache.kafka.common.utils.Exit;
import org.apache.kafka.common.utils.Utils; import org.apache.kafka.common.utils.Utils;
import org.apache.kafka.connect.runtime.WorkerConfig; import org.apache.kafka.connect.runtime.WorkerConfig;
@ -85,7 +86,7 @@ public class ConnectPluginPath {
} catch (ArgumentParserException e) { } catch (ArgumentParserException e) {
parser.handleError(e); parser.handleError(e);
return 1; return 1;
} catch (TerseException e) { } catch (TerseException | ConfigException e) {
err.println(e.getMessage()); err.println(e.getMessage());
return 2; return 2;
} catch (Throwable e) { } catch (Throwable e) {
@ -199,17 +200,17 @@ public class ConnectPluginPath {
return pluginLocations; return pluginLocations;
} }
private static void validatePluginPath(String pluginPath, String configName) throws TerseException { private static void validatePluginPath(String pluginPath, String configName) throws ConfigException {
String trimmed = pluginPath.trim(); String trimmed = pluginPath.trim();
if (trimmed.isEmpty()) { if (trimmed.isEmpty()) {
throw new TerseException("'" + configName + "' must not be empty."); throw new ConfigException("'" + configName + "' must not be empty.");
} }
String[] pluginPathElements = COMMA_WITH_WHITESPACE.split(trimmed, -1); String[] pluginPathElements = COMMA_WITH_WHITESPACE.split(trimmed, -1);
for (String path : pluginPathElements) { for (String path : pluginPathElements) {
if (path.isEmpty()) { if (path.isEmpty()) {
throw new TerseException("'" + configName + "' values must not be empty."); throw new ConfigException("'" + configName + "' values must not be empty.");
} }
} }
} }

View File

@ -341,7 +341,7 @@ public class ConnectPluginPathTest {
"" ""
); );
assertNotEquals(0, res.returnCode); assertNotEquals(0, res.returnCode);
assertTrue("'--plugin-path' must not be empty.\n".equals(res.err)); assertEquals("'--plugin-path' must not be empty.\n", res.err);
} }
@Test @Test
@ -352,7 +352,7 @@ public class ConnectPluginPathTest {
"location-a,,location-b" "location-a,,location-b"
); );
assertNotEquals(0, res.returnCode); assertNotEquals(0, res.returnCode);
assertTrue("'--plugin-path' values must not be empty.\n".equals(res.err)); assertEquals("'--plugin-path' values must not be empty.\n", res.err);
} }
@Test @Test
@ -370,7 +370,7 @@ public class ConnectPluginPathTest {
configPath.toString() configPath.toString()
); );
assertNotEquals(0, res.returnCode); assertNotEquals(0, res.returnCode);
assertTrue("'plugin.path' must not be empty.\n".equals(res.err)); assertEquals("'plugin.path' must not be empty.\n", res.err);
} }
@Test @Test
@ -388,7 +388,7 @@ public class ConnectPluginPathTest {
configPath.toString() configPath.toString()
); );
assertNotEquals(0, res.returnCode); assertNotEquals(0, res.returnCode);
assertTrue("'plugin.path' values must not be empty.\n".equals(res.err)); assertEquals("'plugin.path' values must not be empty.\n", res.err);
} }
private static Map<String, List<String[]>> assertListSuccess(CommandResult result) { private static Map<String, List<String[]>> assertListSuccess(CommandResult result) {