Improved error message when verifying enode syntax with xdns-enabled (#5346)

* updated error message

Signed-off-by: Nischal Sharma <nischal@web3labs.com>

---------

Signed-off-by: Nischal Sharma <nischal@web3labs.com>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/5352/head
Nischal Sharma 2 years ago committed by GitHub
parent 06c38ed8fc
commit 832886d19c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      besu/src/test/java/org/hyperledger/besu/util/LocalPermissioningConfigurationValidatorTest.java
  2. 9
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/EnodeURLImpl.java

@ -212,7 +212,7 @@ public class LocalPermissioningConfigurationValidatorTest {
Files.write(toml, Resources.toByteArray(configFile));
final ImmutableEnodeDnsConfiguration enodeDnsConfiguration =
ImmutableEnodeDnsConfiguration.builder().dnsEnabled(false).updateEnabled(false).build();
ImmutableEnodeDnsConfiguration.builder().dnsEnabled(true).updateEnabled(false).build();
assertThatThrownBy(
() ->
@ -224,7 +224,6 @@ public class LocalPermissioningConfigurationValidatorTest {
toml.toAbsolutePath().toString()))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining(
"Invalid enode URL syntax 'enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@hostname:4567'. "
+ "Enode URL should have the following format 'enode://<node_id>@<ip>:<listening_port>[?discport=<discovery_port>]'. Invalid ip address.");
"Invalid IP address (or DNS query resolved an invalid IP). --Xdns-enabled is true but --Xdns-update-enabled flag is false.");
}
}

@ -80,13 +80,20 @@ public class EnodeURLImpl implements EnodeURL {
checkStringArgumentNotEmpty(value, "Invalid empty value.");
return fromURI(URI.create(value), enodeDnsConfiguration);
} catch (final IllegalArgumentException e) {
String message =
String message = "";
if (enodeDnsConfiguration.dnsEnabled() && !enodeDnsConfiguration.updateEnabled()) {
message =
"Invalid IP address (or DNS query resolved an invalid IP). --Xdns-enabled is true but --Xdns-update-enabled flag is false.";
} else {
message =
String.format(
"Invalid enode URL syntax '%s'. Enode URL should have the following format 'enode://<node_id>@<ip>:<listening_port>[?discport=<discovery_port>]'.",
value);
if (e.getMessage() != null) {
message += " " + e.getMessage();
}
}
throw new IllegalArgumentException(message, e);
}
}

Loading…
Cancel
Save