From ae2a68709a9ade77a8b78205c803dba6a6d71744 Mon Sep 17 00:00:00 2001 From: nsingh Date: Fri, 20 Jan 2017 12:10:04 -0800 Subject: [PATCH 1/2] Fixed issue where exception name was shown in CF proposal --- .../ide/vscode/commons/util/ExceptionUtil.java | 13 +++++++++++++ .../commons/yaml/completion/YTypeAssistContext.java | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/vscode-extensions/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/ExceptionUtil.java b/vscode-extensions/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/ExceptionUtil.java index f1a0494f1..cc5fd29bf 100644 --- a/vscode-extensions/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/ExceptionUtil.java +++ b/vscode-extensions/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/ExceptionUtil.java @@ -64,6 +64,19 @@ public class ExceptionUtil { String msg = cause.getClass().getSimpleName() + ": " + cause.getMessage(); return msg; } + + /** + * + * @param e + * @return a nicer message suitable for display to the user + */ + public static String getMessageForUserDisplay(Throwable e) { + // The message of nested exception is usually more interesting than the + // one on top. + Throwable cause = getDeepestCause(e); + String msg = cause.getMessage(); + return msg; + } public static IllegalStateException notImplemented(String string) { return new IllegalStateException("Not implemented: " + string); diff --git a/vscode-extensions/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/completion/YTypeAssistContext.java b/vscode-extensions/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/completion/YTypeAssistContext.java index e07c817ee..a83d03401 100644 --- a/vscode-extensions/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/completion/YTypeAssistContext.java +++ b/vscode-extensions/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/completion/YTypeAssistContext.java @@ -155,7 +155,7 @@ public class YTypeAssistContext extends AbstractYamlAssistContext { values = typeUtil.getHintValues(type, getSchemaContext()); } catch (Exception e) { DocumentEdits edits = new DocumentEdits(doc.getDocument()); - return ImmutableList.of(completionFactory().errorMessage(ExceptionUtil.getMessage(e), query, type, edits, typeUtil)); + return ImmutableList.of(completionFactory().errorMessage(ExceptionUtil.getMessageForUserDisplay(e), query, type, edits, typeUtil)); } if (values!=null) { ArrayList completions = new ArrayList<>(); From 64b92bab2faf1a3eb1c778399f26274fecd3a378 Mon Sep 17 00:00:00 2001 From: nsingh Date: Fri, 20 Jan 2017 13:10:29 -0800 Subject: [PATCH 2/2] Ensure that null CF hints are returned. The parser used by reconciler expects null if values cannot be resolved by the hints provider. --- .../yaml/ManifestYamlCFBuildpacksProvider.java | 11 +++++++---- .../manifest/yaml/ManifestYamlCFServicesProvider.java | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlCFBuildpacksProvider.java b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlCFBuildpacksProvider.java index 533dea561..96e37eb71 100644 --- a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlCFBuildpacksProvider.java +++ b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlCFBuildpacksProvider.java @@ -28,11 +28,12 @@ public class ManifestYamlCFBuildpacksProvider extends AbstractCFHintsProvider { @Override public Collection getHints(List targets) throws Exception { - List hints = new ArrayList<>(); for (CFTarget cfTarget : targets) { List buildpacks = cfTarget.getBuildpacks(); - if (buildpacks != null) { + if (buildpacks != null && !buildpacks.isEmpty()) { + List hints = new ArrayList<>(); + for (CFBuildpack buildpack : buildpacks) { String name = buildpack.getName(); String label = getBuildpackLabel(cfTarget, buildpack); @@ -41,10 +42,12 @@ public class ManifestYamlCFBuildpacksProvider extends AbstractCFHintsProvider { hints.add(hint); } } + return hints; } } - - return hints; + // Return null if no hints an be resolved rather than empty list (seems to be + // what is expected for parsing for reconciler) + return null; } protected String getBuildpackLabel(CFTarget target, CFBuildpack buildpack) { diff --git a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlCFServicesProvider.java b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlCFServicesProvider.java index f8ab0a655..bf2939fe6 100644 --- a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlCFServicesProvider.java +++ b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlCFServicesProvider.java @@ -28,11 +28,12 @@ public class ManifestYamlCFServicesProvider extends AbstractCFHintsProvider { @Override public Collection getHints(List targets) throws Exception { - List hints = new ArrayList<>(); for (CFTarget cfTarget : targets) { List services = cfTarget.getServices(); - if (services != null) { + if (services != null && !services.isEmpty()) { + List hints = new ArrayList<>(); + for (CFServiceInstance service : services) { String name = service.getName(); String label = getServiceLabel(cfTarget, service); @@ -41,10 +42,12 @@ public class ManifestYamlCFServicesProvider extends AbstractCFHintsProvider { hints.add(hint); } } + return hints; } } - - return hints; + // Return null if no hints an be resolved rather than empty list (seems to be + // what is expected for parsing for reconciler) + return null; } private String getServiceLabel(CFTarget cfClientTarget, CFServiceInstance service) {