From 336d3b424cd03d4385f3b0d42379b45b9c0d8c38 Mon Sep 17 00:00:00 2001 From: Pablo Carle Date: Fri, 7 Oct 2022 14:57:12 +0200 Subject: [PATCH] fix: exception handling in extensions config reader (#2609) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix exception handling Signed-off-by: Pablo Hernán Carle * update license Signed-off-by: Pablo Hernán Carle * improve log messages Signed-off-by: Pablo Hernán Carle Signed-off-by: Pablo Hernán Carle Co-authored-by: Pablo Hernán Carle --- .../extension/ExtensionConfigReader.java | 7 +++++-- .../ExtensionManifestReadException.java | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 apiml-extension-loader/src/main/java/org/zowe/apiml/extension/ExtensionManifestReadException.java diff --git a/apiml-extension-loader/src/main/java/org/zowe/apiml/extension/ExtensionConfigReader.java b/apiml-extension-loader/src/main/java/org/zowe/apiml/extension/ExtensionConfigReader.java index 4f2c66c8fe..57637c6fa1 100644 --- a/apiml-extension-loader/src/main/java/org/zowe/apiml/extension/ExtensionConfigReader.java +++ b/apiml-extension-loader/src/main/java/org/zowe/apiml/extension/ExtensionConfigReader.java @@ -59,7 +59,7 @@ private List getEnabledExtensions() { if (enabledComponents.contains(installedComponent)) { try { extensions.add(readComponentManifest(installedComponent)); - } catch (Exception e) { + } catch (ExtensionManifestReadException e) { log.error("Failed reading component {} manifest", installedComponent, e); } } @@ -75,7 +75,8 @@ private ExtensionDefinition readComponentManifest(String installedComponent) { if (definition.isPresent()) { return definition.get(); } else { - return readComponentManifestWithCharset(Charset.forName("IBM1047"), manifestYamlPath, manifestJsonPath).orElseThrow(() -> new RuntimeException("Could not read manifest in IBM1047 encoding")); + return readComponentManifestWithCharset(Charset.forName("IBM1047"), manifestYamlPath, manifestJsonPath) + .orElseThrow(() -> new ExtensionManifestReadException("Could not read manifest in either " + Charset.defaultCharset() + " nor in IBM1047 encoding")); } } @@ -88,9 +89,11 @@ private Optional readComponentManifestWithCharset(Charset c } else if (Files.exists(jsonPath)) { return Optional.ofNullable(jsonMapper.readValue(new String(Files.readAllBytes(jsonPath), charset), ExtensionDefinition.class)); } else { + log.debug("None of these files were found: {} nor {} ", yamlPath, jsonPath); return Optional.empty(); } } catch (Exception e) { + log.debug("Failed to read {}/{} with charset {}", yamlPath, jsonPath, charset, e); return Optional.empty(); } } diff --git a/apiml-extension-loader/src/main/java/org/zowe/apiml/extension/ExtensionManifestReadException.java b/apiml-extension-loader/src/main/java/org/zowe/apiml/extension/ExtensionManifestReadException.java new file mode 100644 index 0000000000..dae44469f7 --- /dev/null +++ b/apiml-extension-loader/src/main/java/org/zowe/apiml/extension/ExtensionManifestReadException.java @@ -0,0 +1,19 @@ +/* + * This program and the accompanying materials are made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Copyright Contributors to the Zowe Project. + */ + +package org.zowe.apiml.extension; + +public class ExtensionManifestReadException extends RuntimeException { + + public ExtensionManifestReadException(String message) { + super(message); + } + +}