Fixed bug where no-targets error still contains appended information

This commit is contained in:
nsingh
2017-01-24 15:46:48 -08:00
parent e35ae2e0c9
commit 69976eeac8
3 changed files with 23 additions and 12 deletions

View File

@@ -68,6 +68,17 @@ public class ExceptionUtil {
return "An error occurred: " + getSimpleError(e);
}
}
public static String getMessageNoAppendedInformation(Throwable e) {
Throwable deepestCause = ExceptionUtil.getDeepestCause(e);
String msg = deepestCause != null ? deepestCause.getMessage() : null;
if (StringUtil.hasText(msg)) {
return msg;
} else {
return "An error occurred: " + getSimpleError(e);
}
}
public static String getSimpleError(Throwable e) {
return e.getClass().getSimpleName();

View File

@@ -186,12 +186,7 @@ public class YTypeAssistContext extends AbstractYamlAssistContext {
// If value parse exception, do not append any additional information
if (e instanceof ValueParseException) {
String msg = e.getMessage();
if (StringUtil.hasText(msg)) {
return msg;
} else {
return "An error occurred: " + getSimpleError(e);
}
return ExceptionUtil.getMessageNoAppendedInformation(e);
} else {
return ExceptionUtil.getMessage(e);
}

View File

@@ -48,14 +48,19 @@ public abstract class AbstractCFHintsProvider implements Callable<Collection<YVa
hints.addAll(resolvedHints);
}
} catch (Throwable e) {
// Convert any non "no-target" errors to something readable. The
// "no-target" errors
// are generated by the target provider so they should be propagated
// as is without further
// transformation
// Convert any error into something readable to the user as it may
// appear in the content assist
// UI. Do NOT wrap the original exception as the framework may look
// for the deepest cause when
// resolving the error message. Instead, log the full error, and
// only throw a
// new exception with a "nicer" message
Throwable noTargetsError = ExceptionUtil.getThrowable(e, NoTargetsException.class);
if (noTargetsError != null) {
throw new ValueParseException(ExceptionUtil.getMessage(noTargetsError));
// Do not log the no-targets exception as it may be encountered
// frequently
// if a user does not have a CF client installed
throw new ValueParseException(ExceptionUtil.getMessageNoAppendedInformation(noTargetsError));
} else {
// Log any other error
logger.log(Level.SEVERE, ExceptionUtil.getMessage(e), e);