From 81d4fac8c9e431708f7a23aeeec719291cd191c7 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Tue, 25 May 2021 18:16:01 +1000 Subject: [PATCH] non-existent genesis file: clarify error (#2320) * add error message * added a test for non-existent genesis file Signed-off-by: Sally MacFarlane --- .../java/org/hyperledger/besu/cli/BesuCommand.java | 3 ++- .../org/hyperledger/besu/cli/BesuCommandTest.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index a358423f43..41ef4eab62 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -1488,7 +1488,8 @@ public class BesuCommand implements DefaultCommandValues, Runnable { final GenesisConfigFile genesisConfigFile = GenesisConfigFile.fromConfig(genesisConfig()); genesisConfigOptions = genesisConfigFile.getConfigOptions(genesisConfigOverrides); } catch (final Exception e) { - throw new IllegalStateException("Unable to read genesis file for GoQuorum options", e); + throw new ParameterException( + this.commandLine, "Unable to load genesis file. " + e.getCause()); } return genesisConfigOptions; } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index f11f2dda27..835d05d4ea 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -994,6 +994,18 @@ public class BesuCommandTest extends CommandTestAbstract { .startsWith("--network option and --genesis-file option can't be used at the same time."); } + @Test + public void nonExistentGenesisGivesError() throws Exception { + final String nonExistentGenesis = "non-existent-genesis.json"; + parseCommand("--genesis-file", nonExistentGenesis); + + Mockito.verifyZeroInteractions(mockRunnerBuilder); + + assertThat(commandOutput.toString()).isEmpty(); + assertThat(commandErrorOutput.toString()).startsWith("Unable to load genesis file"); + assertThat(commandErrorOutput.toString()).contains(nonExistentGenesis); + } + @Test public void testDnsDiscoveryUrlEthConfig() throws Exception { final ArgumentCaptor networkArg =