@NotNull protected final P4CommandRunner.ServerResultException createServerResultException(@Nullable Error e, @Nls(capitalization = Nls.Capitalization.Sentence) @NotNull String message, @NotNull P4CommandRunner.ErrorCategory category) { return new P4CommandRunner.ServerResultException( new ResultErrorImpl(message, category), e); }
@NotNull protected final P4CommandRunner.ServerResultException createServerResultException(@Nullable Exception e, @Nls(capitalization = Nls.Capitalization.Sentence) @NotNull String message, @NotNull P4CommandRunner.ErrorCategory category) { return new P4CommandRunner.ServerResultException( new ResultErrorImpl(message, category), e); }
public static P4CommandRunner.ServerResultException createException( @NotNull P4CommandRunner.ErrorCategory category, @Nullable String message, @Nullable Throwable t) { // Avoid needing to initialize the VcsBundle by always including an exception with a message. if (t == null) { t = new RuntimeException("blah"); } if (message == null) { if (t.getMessage() == null) { throw new IllegalArgumentException("Better add in a message, or you'll be sorry."); } message = t.getMessage(); } return new P4CommandRunner.ServerResultException(createResultError(category, message), t); }
static <S> Answer<S> forPromise(@NotNull Promise<S> p) { AsyncAnswer<S> ret = new AsyncAnswer<>(); p .then((s) -> { ret.resolve(s); return s; }) .rejected((t) -> { if (t instanceof P4CommandRunner.ServerResultException) { ret.reject((P4CommandRunner.ServerResultException) t); } else { ret.reject(new P4CommandRunner.ServerResultException(new P4CommandRunner.ResultError() { @NotNull @Override public P4CommandRunner.ErrorCategory getCategory() { return P4CommandRunner.ErrorCategory.INTERNAL; } @Nls @NotNull @Override public Optional<String> getMessage() { return Optional.ofNullable(t.getLocalizedMessage()); } }, t)); } }); return ret; }
@Test void map_reject() { AsyncAnswer<Object> answer1 = new AsyncAnswer<>(); Answer<Object> answer2 = answer1.map((c) -> "b"); answer2.whenCompleted((c) -> fail("Should never be called")); P4CommandRunner.ServerResultException sre = new P4CommandRunner.ServerResultException( new P4CommandRunner.ResultError() { @NotNull @Override public P4CommandRunner.ErrorCategory getCategory() { return P4CommandRunner.ErrorCategory.CONNECTION; } @Nls @NotNull @Override public Optional<String> getMessage() { return Optional.empty(); } }); answer2.whenFailed((actual) -> assertSame(sre, actual)); answer1.reject(sre); }
public static P4CommandRunner.ServerResultException createSwarmError(final Exception e) { return new P4CommandRunner.ServerResultException(new P4CommandRunner.ResultError() { @NotNull @Override public P4CommandRunner.ErrorCategory getCategory() { return P4CommandRunner.ErrorCategory.SWARM; } @Nls @NotNull @Override public Optional<String> getMessage() { return Optional.of(e.getLocalizedMessage() == null ? "General swarm problem" : e.getLocalizedMessage()); } }, e); } }
public static P4CommandRunner.ServerResultException createFor(InterruptedException e) { return new P4CommandRunner.ServerResultException(new TimeoutResultError(e)); }
public static P4CommandRunner.ServerResultException createOfflineError() { return new P4CommandRunner.ServerResultException(OFFLINE_RESULT_ERROR); }
public static P4CommandRunner.ServerResultException createFor(CancellationException e) { return new P4CommandRunner.ServerResultException(new TimeoutResultError(e)); }