Improved error message for invalid services
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.manifest.yaml;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.springframework.ide.vscode.commons.util.EnumValueParser;
|
||||
|
||||
public class CFServicesValueParser extends EnumValueParser {
|
||||
|
||||
public CFServicesValueParser(String typeName, Callable<Collection<String>> values) {
|
||||
super(typeName, values);
|
||||
}
|
||||
|
||||
protected String createErrorMessage(String parseString, Collection<String> values) {
|
||||
return "There is no service instance called '" + parseString + "'. Available service instances are: " + values;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -67,7 +67,8 @@ public class ManifestYmlSchema implements YamlSchema {
|
||||
YAtomicType t_service_string = f.yatomic("Service");
|
||||
if (servicesProvider != null) {
|
||||
t_service_string.addHintProvider(servicesProvider);
|
||||
t_service_string.parseWith(ManifestYmlValueParsers.fromHints(t_service_string.toString(), servicesProvider));
|
||||
t_service_string.parseWith(new CFServicesValueParser(t_service_string.toString(),
|
||||
ManifestYmlValueParsers.getValuesFromHints(servicesProvider)));
|
||||
}
|
||||
YType t_services = f.yseq(t_service_string);
|
||||
|
||||
|
||||
@@ -93,6 +93,12 @@ public class ManifestYmlValueParsers {
|
||||
}
|
||||
|
||||
public static ValueParser fromHints(String typeName, Callable<Collection<YValueHint>> hintProvider) {
|
||||
Callable<Collection<String>> values = getValuesFromHints(hintProvider);
|
||||
|
||||
return new EnumValueParser(typeName, values);
|
||||
}
|
||||
|
||||
public static Callable<Collection<String>> getValuesFromHints(Callable<Collection<YValueHint>> hintProvider) {
|
||||
Callable<Collection<String>> values= () -> {
|
||||
Collection<YValueHint> hints = hintProvider.call();
|
||||
if (hints != null) {
|
||||
@@ -106,8 +112,7 @@ public class ManifestYmlValueParsers {
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
return new EnumValueParser(typeName, values);
|
||||
return values;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user