Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-23930 ensurePublicException use original exception as cause #4866

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static Throwable ensurePublicException(Throwable e) {
*/
// TODO: consider removing after IGNITE-22721 gets resolved.
private static <T extends Throwable & TraceableException> Throwable copyExceptionWithCauseIfPossible(T e) {
Throwable copy = ExceptionUtils.copyExceptionWithCause(e.getClass(), e.traceId(), e.code(), e.getMessage(), e);
Throwable copy = ExceptionUtils.copyExceptionWithCause(e.getClass(), e.traceId(), e.code(), e.getMessage(), e.getCause());
if (copy != null) {
return copy;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.ignite.internal.util;

import static org.apache.ignite.lang.ErrorGroups.Common.INTERNAL_ERR;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;

import java.util.UUID;
import org.apache.ignite.lang.IgniteException;
import org.junit.jupiter.api.Test;

class ViewUtilsTest {

@Test
void ensurePublicException() {
UUID traceId = UUID.randomUUID();
IgniteException exception = new IgniteException(traceId, INTERNAL_ERR, "message", new RuntimeException("cause"));
Throwable publicException = ViewUtils.ensurePublicException(exception);

assertThat(publicException.getMessage(), is("message"));
assertThat(publicException.getCause(), instanceOf(RuntimeException.class));
assertThat(publicException.getCause().getMessage(), is("cause"));

assertThat(publicException, instanceOf(IgniteException.class));
IgniteException igniteException = (IgniteException) publicException;
assertThat(igniteException.traceId(), is(traceId));
assertThat(igniteException.code(), is(INTERNAL_ERR));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,7 @@ private static IgniteException getExceptionInJobExecutionAsync(JobExecution<Stri
}

private static IgniteException getExceptionInJobExecutionSync(Supplier<String> execution) {
IgniteException ex = assertThrows(IgniteException.class, execution::get);

return (IgniteException) ex.getCause();
return assertThrows(IgniteException.class, execution::get);
}

private static void assertComputeExceptionWithClassAndMessage(IgniteException cause) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,6 @@ void testExceptionHasHint() {

IgniteException ex = assertThrows(IgniteException.class, () -> client.sql().execute(null, "select x from bad"));
assertEquals("To see the full stack trace set clientConnector.sendServerExceptionStackTraceToClient:true",
ex.getCause().getCause().getCause().getCause().getMessage());
ex.getCause().getCause().getCause().getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void testKeyValueView(TestEnvironment env) {
rwTx -> {
IgniteException ex = assertThrows(IgniteException.class,
() -> tab.keyValueView(KeyObject.class, Integer.class).put(rwTx, key, 1));
assertThat(ex.getCause().getCause(), is(instanceOf(IllegalArgumentException.class)));
assertThat(ex.getCause(), is(instanceOf(IllegalArgumentException.class)));

kvView.put(rwTx, key, null);

Expand Down