Skip to content

Commit

Permalink
Report invalid options in config YAML to user (#6000)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmygchen authored Aug 1, 2022
1 parent eebba74 commit a9f80cb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,12 @@ public int parse(final String[] args) {
final AdditionalParamsProvider additionalParamsProvider =
additionalParamsProvider(commandLine, configFile);

final Map<String, String> additionalParams =
additionalParamsProvider.getAdditionalParams(potentialAdditionalParams);
final Map<String, String> additionalParams;
try {
additionalParams = additionalParamsProvider.getAdditionalParams(potentialAdditionalParams);
} catch (ParameterException e) {
return handleParseException(e, args);
}

// build new argument list by concatenating original args and the additional params
final String[] enrichedArgs =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ public void unknownOptionShouldDisplayShortHelpMessage() {
assertThat(str).doesNotContain("Default");
}

@Test
public void unknownOptionInConfigFileShouldDisplayShortHelpMessage() throws IOException {
final Path configFile = createInvalidConfigFile();
final String[] args = {CONFIG_FILE_OPTION_NAME, configFile.toString()};

beaconNodeCommand.parse(args);
String str = getCommandLineOutput();
assertThat(str).contains("Unknown option");
assertThat(str).contains("To display full help:");
assertThat(str).contains("--help");
assertThat(str).doesNotContain("Default");
}

@Test
public void unmatchedOptionsNotAllowedAsOptionParameters() {
final String[] args = {"--eth1-endpoints http://localhost:8545 --foo"};
Expand Down Expand Up @@ -320,7 +333,7 @@ public void shouldSetNatMethod() {
}

private Path createConfigFile() throws IOException {
final URL configFile = this.getClass().getResource("/complete_config.yaml");
final URL configFile = BeaconNodeCommandTest.class.getResource("/complete_config.yaml");
final String updatedConfig =
Resources.toString(configFile, UTF_8)
.replace(
Expand All @@ -329,6 +342,13 @@ private Path createConfigFile() throws IOException {
return createTempFile(updatedConfig.getBytes(UTF_8));
}

private Path createInvalidConfigFile() throws IOException {
final URL configFile = BeaconNodeCommandTest.class.getResource("/complete_config.yaml");
final String updatedConfig =
Resources.toString(configFile, UTF_8).replace("network:", "xnetwork:");
return createTempFile(updatedConfig.getBytes(UTF_8));
}

private String[] createCliArgs() {
return new String[] {
"--network",
Expand Down

0 comments on commit a9f80cb

Please sign in to comment.