Skip to content

Commit e7916e0

Browse files
committed
Add meaningful descriptions to ConstantDerivedException (fixes #63)
1 parent a4b8f14 commit e7916e0

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/main/java/org/lmdbjava/ResultCodeMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ static void checkRc(final int rc) throws LmdbNativeException {
110110
if (constant == null) {
111111
throw new IllegalArgumentException("Unknown result code " + rc);
112112
}
113-
throw new LmdbNativeException.ConstantDerviedException(rc, constant.name());
113+
final String msg = constant.name() + " " + constant.toString();
114+
throw new LmdbNativeException.ConstantDerviedException(rc, msg);
114115
}
115116

116117
}

src/test/java/org/lmdbjava/ResultCodeMapperTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static java.lang.Integer.MAX_VALUE;
2424
import java.util.HashSet;
2525
import java.util.Set;
26+
import static org.hamcrest.CoreMatchers.containsString;
2627
import static org.hamcrest.CoreMatchers.is;
2728
import static org.hamcrest.CoreMatchers.notNullValue;
2829
import static org.hamcrest.MatcherAssert.assertThat;
@@ -107,6 +108,16 @@ public void checkErrConstantDerived() {
107108
checkRc(20);
108109
}
109110

111+
@Test
112+
public void checkErrConstantDerivedMessage() {
113+
try {
114+
checkRc(2);
115+
fail("Should have raised exception");
116+
} catch (final ConstantDerviedException ex) {
117+
assertThat(ex.getMessage(), containsString("No such file or directory"));
118+
}
119+
}
120+
110121
@Test(expected = FullException.class)
111122
public void checkErrCursorFull() {
112123
checkRc(MDB_CURSOR_FULL);

0 commit comments

Comments
 (0)