Skip to content

Commit

Permalink
fix: ignore conversion exceptions for plugin configuration to prevent…
Browse files Browse the repository at this point in the history
… program errors (#6924)

#### What type of PR is this?
/kind bug
/area plugin
/milestone 2.20.x

#### What this PR does / why we need it:
修复插件配置可能因为缺少校验导致使用时类型转换失败从而影响 Halo 使用的问题

#### Which issue(s) this PR fixes:
Fixes #6899

#### Does this PR introduce a user-facing change?
```release-note
修复插件配置可能因为缺少校验导致使用时类型转换失败从而影响 Halo 使用的问题
```
  • Loading branch information
guqing authored Oct 23, 2024
1 parent fae03d4 commit 17ec34c
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
Expand All @@ -26,7 +27,6 @@
import run.halo.app.extension.controller.Controller;
import run.halo.app.extension.controller.ControllerBuilder;
import run.halo.app.extension.controller.Reconciler;
import run.halo.app.infra.utils.JsonParseException;
import run.halo.app.infra.utils.JsonUtils;

/**
Expand All @@ -35,6 +35,7 @@
* @author guqing
* @since 2.0.0
*/
@Slf4j
public class DefaultReactiveSettingFetcher
implements ReactiveSettingFetcher, Reconciler<Reconciler.Request>, DisposableBean,
ApplicationContextAware {
Expand Down Expand Up @@ -130,12 +131,21 @@ private JsonNode readTree(String json) {
try {
return JsonUtils.DEFAULT_JSON_MAPPER.readTree(json);
} catch (JsonProcessingException e) {
throw new JsonParseException(e);
// ignore
log.error("Failed to parse plugin [{}] config json: [{}]", pluginName, json, e);
}
return JsonNodeFactory.instance.missingNode();
}

private <T> T convertValue(JsonNode jsonNode, Class<T> clazz) {
return JsonUtils.DEFAULT_JSON_MAPPER.convertValue(jsonNode, clazz);
try {
return JsonUtils.DEFAULT_JSON_MAPPER.convertValue(jsonNode, clazz);
} catch (IllegalArgumentException e) {
// ignore
log.error("Failed to convert plugin [{}] configMap [{}] to class [{}]",
pluginName, configMapName, clazz, e);
}
return null;
}

@NonNull
Expand Down

0 comments on commit 17ec34c

Please sign in to comment.