Skip to content

Commit

Permalink
Handle fatal error
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyeh committed Nov 28, 2023
1 parent 766e0fe commit 77f50f7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
13 changes: 12 additions & 1 deletion teku/src/main/java/tech/pegasys/teku/cli/BeaconNodeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down

0 comments on commit 77f50f7

Please sign in to comment.