Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore conversion exceptions for plugin configuration to prevent program errors #6924

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading