Skip to content

Commit

Permalink
Merge pull request #3946 from paulmillar/fix/2.16/rb10875
Browse files Browse the repository at this point in the history
pool: fix error message for failed active FTP transfers
  • Loading branch information
Jürgen Starek committed Apr 9, 2018
2 parents 4f57bb2 + ac2bc68 commit 39558c9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
13 changes: 8 additions & 5 deletions modules/cells/src/main/java/dmg/util/Exceptions.java
Expand Up @@ -58,15 +58,18 @@ public static String getMessageWithCauses(Throwable t)
* enclosingType is reached. If enclosingType does not support wrapping
* then {@literal cause} is returned and a warning is logged.
* <p />
* Note that the wrapped exception will contain only a message and possibly
* the {@literal cause} as the triggering exception; in particular, any
* additional information from {@literal cause} is not copied into the
* wrapped exception.
* Note that the wrapping exception will have a message constructed by
* concatenating the prefix, the String literal ": ", and a cause-specific
* message. If the cause has a non-null message then this is used as the
* cause-specific message, otherwise the cause class simple name is used.
*/
public static <T extends Exception> T wrap(String message, T cause, Class<T> enclosingType)
public static <T extends Exception> T wrap(String prefix, T cause, Class<T> enclosingType)
{
ReflectiveOperationException lastException = null;

String causeMessage = cause.getMessage() == null ? cause.getClass().getSimpleName() : cause.getMessage();
String message = prefix + ": " + causeMessage;

Class type = cause.getClass();
while (enclosingType.isAssignableFrom(type)) {
try {
Expand Down
8 changes: 4 additions & 4 deletions modules/cells/src/test/java/dmg/util/ExceptionsTests.java
Expand Up @@ -49,7 +49,7 @@ public void shouldWrapWithCauseInSimpleCase()
IOException wrapped = Exceptions.wrap("Wrapped message", cause, IOException.class);

assertThat(wrapped, is(notNullValue()));
assertThat(wrapped.getMessage(), is(equalTo("Wrapped message")));
assertThat(wrapped.getMessage(), is(equalTo("Wrapped message: Something went wrong")));
assertThat(wrapped.getCause(), is(cause));
assertThat(wrapped.getClass(), is(equalTo(IOException.class)));

Expand All @@ -64,7 +64,7 @@ public void shouldWrapWithCauseInBroaderContext()
Exception wrapped = Exceptions.wrap("Wrapped message", cause, Exception.class);

assertThat(wrapped, is(notNullValue()));
assertThat(wrapped.getMessage(), is(equalTo("Wrapped message")));
assertThat(wrapped.getMessage(), is(equalTo("Wrapped message: Something went wrong")));
assertThat(wrapped.getCause(), is(cause));
assertThat(wrapped.getClass(), is(equalTo(IOException.class)));

Expand All @@ -82,7 +82,7 @@ public void shouldWapWithMessageIfExceptionHasNoStringThrowableConstructor()
Exception wrapped = Exceptions.wrap("Wrapped message", cause, SocketException.class);

assertThat(wrapped, is(notNullValue()));
assertThat(wrapped.getMessage(), is(equalTo("Wrapped message")));
assertThat(wrapped.getMessage(), is(equalTo("Wrapped message: Something went wrong")));
assertThat(wrapped.getCause(), is(nullValue()));
assertThat(wrapped.getClass(), is(equalTo(SocketException.class)));

Expand All @@ -99,7 +99,7 @@ public void shouldUseBroaderExceptionIfCannotWrap()
Exception wrapped = Exceptions.wrap("Wrapped message", cause, Exception.class);

assertThat(wrapped, is(notNullValue()));
assertThat(wrapped.getMessage(), is(equalTo("Wrapped message")));
assertThat(wrapped.getMessage(), is(equalTo("Wrapped message: " + cause.getMessage())));
assertThat(wrapped.getCause(), is(cause));
assertThat(wrapped.getClass(), is(equalTo(Exception.class)));

Expand Down
Expand Up @@ -310,12 +310,10 @@ public void transfer(RepositoryChannel fileChannel, Role role,
} catch (BindException | ConnectException | NoRouteToHostException |
PortUnreachableException | UnknownHostException e) {
throw Exceptions.wrap("Failed to connect " +
mode.getRemoteAddressDescription() + ": " + e.getMessage(),
e, IOException.class);
mode.getRemoteAddressDescription(), e, IOException.class);
} catch (IOException e) {
throw Exceptions.wrap("Problem while connected to " +
mode.getRemoteAddressDescription() + ": " + e.getMessage(),
e, IOException.class);
mode.getRemoteAddressDescription(), e, IOException.class);
} finally {
_inProgress = false;

Expand Down

0 comments on commit 39558c9

Please sign in to comment.