From 77f50f787de02c60a35c499505ce7b4bb35a11d2 Mon Sep 17 00:00:00 2001 From: courtneyeh Date: Tue, 28 Nov 2023 15:05:26 +1100 Subject: [PATCH] Handle fatal error --- .../pegasys/teku/cli/BeaconNodeCommand.java | 13 +++++++++- .../client/NoValidatorKeysStateException.java | 24 +++++++++++++++++++ .../client/ValidatorClientService.java | 2 +- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 validator/client/src/main/java/tech/pegasys/teku/validator/client/NoValidatorKeysStateException.java diff --git a/teku/src/main/java/tech/pegasys/teku/cli/BeaconNodeCommand.java b/teku/src/main/java/tech/pegasys/teku/cli/BeaconNodeCommand.java index a554e70eefd..8098f5a03bb 100644 --- a/teku/src/main/java/tech/pegasys/teku/cli/BeaconNodeCommand.java +++ b/teku/src/main/java/tech/pegasys/teku/cli/BeaconNodeCommand.java @@ -74,6 +74,7 @@ import tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory; import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.storage.server.DatabaseStorageException; +import tech.pegasys.teku.validator.client.NoValidatorKeysStateException; @SuppressWarnings("unused") @Command( @@ -352,7 +353,17 @@ public Integer call() { } public void reportUnexpectedError(final Throwable t) { - getLogger().fatal("Teku failed to start", t); + if (t instanceof NoValidatorKeysStateException) { + getLogger().fatal("Teku failed to start: " + t.getMessage()); + } else { + getLogger().fatal("Teku failed to start", t); + } + errorWriter.println("Teku failed to start: " + t.getMessage()); + printUsage(errorWriter); + } + + public void reportUnexpectedErrorNoStacktrace(final Throwable t) { + getLogger().fatal("Teku failed to start", t.getMessage()); errorWriter.println("Teku failed to start: " + t.getMessage()); printUsage(errorWriter); } diff --git a/validator/client/src/main/java/tech/pegasys/teku/validator/client/NoValidatorKeysStateException.java b/validator/client/src/main/java/tech/pegasys/teku/validator/client/NoValidatorKeysStateException.java new file mode 100644 index 00000000000..c22709976a4 --- /dev/null +++ b/validator/client/src/main/java/tech/pegasys/teku/validator/client/NoValidatorKeysStateException.java @@ -0,0 +1,24 @@ +/* + * Copyright Consensys Software Inc., 2023 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package tech.pegasys.teku.validator.client; + +public class NoValidatorKeysStateException extends IllegalStateException { + public NoValidatorKeysStateException(String message, Throwable cause) { + super(message, cause); + } + + public NoValidatorKeysStateException(String message) { + super(message); + } +} diff --git a/validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorClientService.java b/validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorClientService.java index 5faed6f7687..aeaec99f7cc 100644 --- a/validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorClientService.java +++ b/validator/client/src/main/java/tech/pegasys/teku/validator/client/ValidatorClientService.java @@ -272,7 +272,7 @@ public static ValidatorClientService create( if (validatorConfig.isExitWhenNoValidatorKeysEnabled() && validatorLoader.getOwnedValidators().getActiveValidators().size() == 0) { - throw new IllegalStateException( + throw new NoValidatorKeysStateException( "No loaded validators when --exit-when-no-validator-keys-enabled option is false"); }