-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mention exception in log message on failures
- Loading branch information
1 parent
3bd4745
commit 3639bcf
Showing
3 changed files
with
65 additions
and
5 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/ExceptionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (C) Gustav Karlsson | ||
* | ||
* <p>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 | ||
* | ||
* <p>http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* <p>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 com.github.kagkarlsson.scheduler; | ||
|
||
final class ExceptionUtils { | ||
|
||
static String describe(Throwable t) { | ||
if (t == null) { | ||
return null; | ||
} | ||
|
||
String typeDescription = t.getClass().getSimpleName(); | ||
String message = t.getMessage(); | ||
return typeDescription + (message != null ? ": '" + message + "'" : ""); | ||
} | ||
|
||
private ExceptionUtils() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/ExceptionUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.github.kagkarlsson.scheduler; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
||
import java.io.IOException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ExceptionUtilsTest { | ||
|
||
@Test | ||
void exceptionWithNoMessageDescribedAsItsClassSimpleName() { | ||
assertThat( | ||
ExceptionUtils.describe(new IllegalArgumentException()), is("IllegalArgumentException")); | ||
} | ||
|
||
@Test | ||
void exceptionDescribedAsClassSimpleNameAndMessage() { | ||
assertThat( | ||
ExceptionUtils.describe(new IOException("timed out")), is("IOException: 'timed out'")); | ||
} | ||
|
||
@Test | ||
void describingNullIsNull() { | ||
assertThat(ExceptionUtils.describe(null), is(nullValue())); | ||
} | ||
} |