Make error information more specifically
This commit is contained in:
parent
9651284ad1
commit
8162533179
@ -317,9 +317,7 @@ public class InstanceController {
|
|||||||
instance.setMetadata(UtilsAndCommons.parseMetadata(metadata));
|
instance.setMetadata(UtilsAndCommons.parseMetadata(metadata));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!instance.validate()) {
|
instance.validate();
|
||||||
throw new NacosException(NacosException.INVALID_PARAM, "instance format invalid:" + instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ package com.alibaba.nacos.naming.core;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
import com.alibaba.nacos.naming.exception.NacosException;
|
||||||
import com.alibaba.nacos.naming.healthcheck.HealthCheckStatus;
|
import com.alibaba.nacos.naming.healthcheck.HealthCheckStatus;
|
||||||
import com.alibaba.nacos.naming.misc.Loggers;
|
import com.alibaba.nacos.naming.misc.Loggers;
|
||||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||||
@ -197,7 +198,9 @@ public class Instance extends com.alibaba.nacos.api.naming.pojo.Instance impleme
|
|||||||
ip.setWeight(0.0D);
|
ip.setWeight(0.0D);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ip.validate()) {
|
try {
|
||||||
|
ip.validate();
|
||||||
|
} catch (NacosException e) {
|
||||||
throw new IllegalArgumentException("malformed ip config: " + json);
|
throw new IllegalArgumentException("malformed ip config: " + json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,19 +301,19 @@ public class Instance extends com.alibaba.nacos.api.naming.pojo.Instance impleme
|
|||||||
return getIp() + "#" + getPort() + "#" + getClusterName() + "#" + getServiceName();
|
return getIp() + "#" + getPort() + "#" + getClusterName() + "#" + getServiceName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean validate() {
|
public void validate() throws NacosException {
|
||||||
if (onlyContainsDigitAndDot()) {
|
if (onlyContainsDigitAndDot()) {
|
||||||
Matcher matcher = IP_PATTERN.matcher(getIp() + ":" + getPort());
|
Matcher matcher = IP_PATTERN.matcher(getIp() + ":" + getPort());
|
||||||
if (!matcher.matches()) {
|
if (!matcher.matches()) {
|
||||||
return false;
|
throw new NacosException(NacosException.INVALID_PARAM, "instance format invalid: Your IP address is spelled incorrectly");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getWeight() > MAX_WEIGHT_VALUE || getWeight() < MIN_WEIGHT_VALUE) {
|
if (getWeight() > MAX_WEIGHT_VALUE || getWeight() < MIN_WEIGHT_VALUE) {
|
||||||
return false;
|
throw new NacosException(NacosException.INVALID_PARAM, "instance format invalid: The weights range from " +
|
||||||
|
MIN_WEIGHT_VALUE + " to " + MAX_WEIGHT_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean onlyContainsDigitAndDot() {
|
private boolean onlyContainsDigitAndDot() {
|
||||||
|
Loading…
Reference in New Issue
Block a user