Skip to content

Commit

Permalink
fix: exception handling in extensions config reader (#2609)
Browse files Browse the repository at this point in the history
* fix exception handling

Signed-off-by: Pablo Hernán Carle <[email protected]>

* update license

Signed-off-by: Pablo Hernán Carle <[email protected]>

* improve log messages

Signed-off-by: Pablo Hernán Carle <[email protected]>

Signed-off-by: Pablo Hernán Carle <[email protected]>
Co-authored-by: Pablo Hernán Carle <[email protected]>
  • Loading branch information
pablocarle and Pablo Hernán Carle authored Oct 7, 2022
1 parent 1c46df4 commit 336d3b4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private List<ExtensionDefinition> getEnabledExtensions() {
if (enabledComponents.contains(installedComponent)) {
try {
extensions.add(readComponentManifest(installedComponent));
} catch (Exception e) {
} catch (ExtensionManifestReadException e) {
log.error("Failed reading component {} manifest", installedComponent, e);
}
}
Expand All @@ -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"));
}
}

Expand All @@ -88,9 +89,11 @@ private Optional<ExtensionDefinition> 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();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}

0 comments on commit 336d3b4

Please sign in to comment.