Skip to content

Commit

Permalink
Revert "Include a better error message to debug nomulus tool not work…
Browse files Browse the repository at this point in the history
…ing (#2275)" (#2342)

This reverts commit 64f5971.

The catch block is too broad and most of the times the errors caught is
because `command.run()` failed and it had nothing to do with getting
the transaction manager. The `runCommand` method is already wrapped in a try
block that checks for `LoginRequiredException` and gives the appropriate
error message.

We need to re-assess the situation when the next time we encounter a
login issue that did not trigger `LoginRequiredException`. A blanket try
catch block is not the solution and only makes the situation more
confusing.

<!-- Reviewable:start -->
- - -
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/google/nomulus/2342)
<!-- Reviewable:end -->
  • Loading branch information
jianglai authored Feb 28, 2024
1 parent 02fd6d4 commit bf877f4
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions core/src/main/java/google/registry/tools/RegistryCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.beust.jcommander.ParameterException;
import com.beust.jcommander.Parameters;
import com.beust.jcommander.ParametersDelegate;
import com.google.common.base.Ascii;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
Expand Down Expand Up @@ -219,21 +218,12 @@ private void runCommand(Command command) throws Exception {

// Reset the JPA transaction manager after every command to avoid a situation where a test can
// interfere with other tests
try {
JpaTransactionManager cachedJpaTm = tm();
TransactionManagerFactory.setJpaTm(() -> component.nomulusToolJpaTransactionManager().get());
TransactionManagerFactory.setReplicaJpaTm(
() -> component.nomulusToolReplicaJpaTransactionManager().get());
command.run();
TransactionManagerFactory.setJpaTm(() -> cachedJpaTm);
} catch (Exception e) {
String env = Ascii.toLowerCase(environment.name());
System.err.printf(
"Could not get tool transaction manager; try running nomulus -e %s logout "
+ "and then nomulus -e %s login.\n",
env, env);
throw e;
}
JpaTransactionManager cachedJpaTm = tm();
TransactionManagerFactory.setJpaTm(() -> component.nomulusToolJpaTransactionManager().get());
TransactionManagerFactory.setReplicaJpaTm(
() -> component.nomulusToolReplicaJpaTransactionManager().get());
command.run();
TransactionManagerFactory.setJpaTm(() -> cachedJpaTm);
}

void setEnvironment(RegistryToolEnvironment environment) {
Expand Down

0 comments on commit bf877f4

Please sign in to comment.