File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed
Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,11 @@ public MDB_envinfo(jnr.ffi.Runtime runtime) {
8585
8686 public interface Lmdb {
8787
88+ /**
89+ * Return the error description for this result code.
90+ */
91+ String mdb_strerror (int rc );
92+
8893 Pointer mdb_version (IntByReference major , IntByReference minor , IntByReference patch );
8994
9095 /**
Original file line number Diff line number Diff line change 2323 */
2424public final class Meta {
2525
26+ /**
27+ * Fetches the LMDB error code description.
28+ * <p>
29+ * End users should not need this method, as LmdbJava converts all LMDB
30+ * exceptions into a typed Java exception that incorporates the error code.
31+ * However it is provided here for verification and troubleshooting (eg if the
32+ * user wishes to see the original LMDB description of the error code, or
33+ * there is a newer library version etc).
34+ *
35+ * @param err the error code returned from LMDB
36+ * @return the description
37+ */
38+ public static String error (final int err ) {
39+ return lib .mdb_strerror (err );
40+ }
41+
2642 /**
2743 * Obtains the LMDB C library version information.
2844 *
Original file line number Diff line number Diff line change 55import static org .hamcrest .CoreMatchers .nullValue ;
66import static org .hamcrest .MatcherAssert .assertThat ;
77import org .junit .Test ;
8+ import static org .lmdbjava .LmdbNativeException .PageCorruptedException .MDB_CORRUPTED ;
89import org .lmdbjava .Meta .Version ;
10+ import static org .lmdbjava .Meta .error ;
911import static org .lmdbjava .TestUtils .invokePrivateConstructor ;
1012
1113public class MetaTest {
@@ -15,11 +17,18 @@ public void coverPrivateConstructors() throws Exception {
1517 invokePrivateConstructor (Meta .class );
1618 }
1719
20+ @ Test
21+ public void errCode () {
22+ assertThat (error (MDB_CORRUPTED ), is (
23+ "MDB_CORRUPTED: Located page was wrong type" ));
24+ }
25+
1826 @ Test
1927 public void version () throws Exception {
2028 final Version v = Meta .version ();
2129 assertThat (v , not (nullValue ()));
2230 assertThat (v .major , is (0 ));
2331 assertThat (v .minor , is (9 ));
2432 }
33+
2534}
You can’t perform that action at this time.
0 commit comments