Include invalid value in Enode error message (#3112)

* Include invalid value in Enode error message.

Makes it much easier for users to identify their mistake if the CLI argument after `--bootnodes <some-valid-enode>` has a typo. PicoCLI will treat any unrecognised option as another bootnode so it's very confusing to get an invalid enode message when the enode is fine and it's the next argument that's incorrect.

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>

Co-authored-by: Sally MacFarlane <sally.macfarlane@consensys.net>
pull/3114/head
Adrian Sutton 3 years ago committed by GitHub
parent ed40d51e87
commit 9c5d1d5cb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 4
      besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
  3. 6
      besu/src/test/java/org/hyperledger/besu/util/LocalPermissioningConfigurationValidatorTest.java
  4. 4
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/EnodeURLImpl.java

@ -5,6 +5,7 @@
### Additions and Improvements
- Adding support of the NO_COLOR environment variable as described in the [NO_COLOR](https://no-color.org/) standard [#3085](https://github.com/hyperledger/besu/pull/3085)
- Add `privx_findFlexiblePrivacyGroup` RPC Method, `privx_findOnchainPrivacyGroup` will be removed in a future release [#3075](https://github.com/hyperledger/besu/pull/3075)
- The invalid value is now shown when `--bootnodes` cannot parse an item to make it easier to identify which option is invalid.
### Bug Fixes
### Early Access Features

@ -1305,7 +1305,7 @@ public class BesuCommandTest extends CommandTestAbstract {
parseCommand("--bootnodes", "invalid_enode_url");
assertThat(commandOutput.toString()).isEmpty();
final String expectedErrorOutputStart =
"Invalid enode URL syntax. Enode URL should have the following format "
"Invalid enode URL syntax 'invalid_enode_url'. Enode URL should have the following format "
+ "'enode://<node_id>@<ip>:<listening_port>[?discport=<discovery_port>]'.";
assertThat(commandErrorOutput.toString()).startsWith(expectedErrorOutputStart);
}
@ -1330,7 +1330,7 @@ public class BesuCommandTest extends CommandTestAbstract {
parseCommand("--bootnodes=invalid_enode_url");
assertThat(commandOutput.toString()).isEmpty();
final String expectedErrorOutputStart =
"Invalid enode URL syntax. Enode URL should have the following format "
"Invalid enode URL syntax 'invalid_enode_url'. Enode URL should have the following format "
+ "'enode://<node_id>@<ip>:<listening_port>[?discport=<discovery_port>]'.";
assertThat(commandErrorOutput.toString()).startsWith(expectedErrorOutputStart);
}

@ -196,7 +196,8 @@ public class LocalPermissioningConfigurationValidatorTest {
toml.toAbsolutePath().toString()))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining(
"Invalid enode URL syntax. Enode URL should have the following format 'enode://<node_id>@<ip>:<listening_port>[?discport=<discovery_port>]'. Invalid ip address.");
"Invalid enode URL syntax 'enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@localhost:4567'. "
+ "Enode URL should have the following format 'enode://<node_id>@<ip>:<listening_port>[?discport=<discovery_port>]'. Invalid ip address.");
}
@Test
@ -220,6 +221,7 @@ public class LocalPermissioningConfigurationValidatorTest {
toml.toAbsolutePath().toString()))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining(
"Invalid enode URL syntax. Enode URL should have the following format 'enode://<node_id>@<ip>:<listening_port>[?discport=<discovery_port>]'. Invalid ip address.");
"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.");
}
}

@ -81,7 +81,9 @@ public class EnodeURLImpl implements EnodeURL {
return fromURI(URI.create(value), enodeDnsConfiguration);
} catch (IllegalArgumentException e) {
String message =
"Invalid enode URL syntax. Enode URL should have the following format 'enode://<node_id>@<ip>:<listening_port>[?discport=<discovery_port>]'.";
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();
}

Loading…
Cancel
Save