gnodet-bot commented on code in PR #29805:
URL: https://github.com/apache/camel/pull/29805#discussion_r4565778816
##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/PluginHelper.java:
##########
@@ -187,16 +194,22 @@ public static boolean isPluginCommand(String command) {
if (Arrays.stream(PluginType.values()).anyMatch(p ->
p.getCommand().equals(command))) {
return true;
}
- JsonObject config = getPluginConfig();
- if (config != null) {
- JsonObject plugins = config.getMap("plugins");
- for (String pluginKey : plugins.keySet()) {
- JsonObject properties = plugins.getMap(pluginKey);
- String name = properties.getOrDefault("name",
pluginKey).toString();
- if (command.equals(properties.getOrDefault("command",
name).toString())) {
- return true;
+ try {
+ JsonObject config = getPluginConfig();
+ if (config != null) {
+ JsonObject plugins = config.getMap("plugins");
+ if (plugins != null) {
+ for (String pluginKey : plugins.keySet()) {
+ JsonObject properties = plugins.getMap(pluginKey);
+ String name = properties.getOrDefault("name",
pluginKey).toString();
+ if (command.equals(properties.getOrDefault("command",
name).toString())) {
+ return true;
+ }
+ }
}
}
+ } catch (Exception e) {
+ // corrupt plugin config — treat as no plugins configured
}
Review Comment:
⚠️ **Silent exception swallow** — `isPluginCommand` catches a corrupt plugin
config silently. If the config is corrupt, the user's installed plugin command
won't be recognized and will fall through to `camel: unknown command`, with no
hint about why. `getActivePlugins` warns for the same failure — same fix
applies here (a `LOG.debug(...)` would at least surface under `--debug`):
```suggestion
} catch (Exception e) {
// corrupt plugin config — treat as no plugins configured
LOG.debug("Could not load plugin config in isPluginCommand: {}",
e.getMessage(), e);
}
```
##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java:
##########
@@ -600,12 +600,16 @@ void printAvailablePlugins() {
}
Set<String> installed = new HashSet<>();
- JsonObject config = PluginHelper.getPluginConfig();
- if (config != null) {
- JsonObject plugins = config.getMap("plugins");
- if (plugins != null) {
- installed.addAll(plugins.keySet());
+ try {
+ JsonObject config = PluginHelper.getPluginConfig();
+ if (config != null) {
+ JsonObject plugins = config.getMap("plugins");
+ if (plugins != null) {
+ installed.addAll(plugins.keySet());
+ }
}
+ } catch (Exception e) {
+ // corrupt plugin config — don't crash the help/banner output
}
Review Comment:
⚠️ **Silent exception swallow** — `printAvailablePlugins` catches a corrupt
plugin config with no user-visible warning. Meanwhile `getActivePlugins` (added
in this same PR) calls `printErr("Warning: " + e.getMessage() + "…")` for the
same failure class.
Consider adding at least a debug/trace log here so the inconsistency is
resolved and a user whose installed plugins have vanished from the banner has
some chance of diagnosing why:
```suggestion
} catch (Exception e) {
// corrupt plugin config — don't crash the help/banner output
main.getOut().printErr("Warning: " + e.getMessage() + ". Use
'camel plugin' commands to fix or delete the file.");
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]