Improve error logging.
This commit is contained in:
parent
53bf09df27
commit
3d4e3aa66d
@ -162,8 +162,9 @@ afterEvaluate {
|
||||
}
|
||||
|
||||
signing {
|
||||
required { isReleaseBuild() && gradle.taskGraph.hasTask("publish") }
|
||||
sign publishing.publications.mavenJava
|
||||
required { false }
|
||||
// required { isReleaseBuild() && gradle.taskGraph.hasTask("publish") }
|
||||
// sign publishing.publications.mavenJava
|
||||
}
|
||||
|
||||
artifacts {
|
||||
|
||||
@ -960,7 +960,7 @@ public class DatabaseGeneralTest extends AndroidTestCase implements PerformanceT
|
||||
assertFalse(mDatabase.isOpen());
|
||||
assertTrue(dbfile.exists());
|
||||
try {
|
||||
errorHandler.onCorruption(mDatabase);
|
||||
errorHandler.onCorruption(mDatabase, "");
|
||||
if(SQLiteDatabase.hasCodec()){
|
||||
assertTrue(dbfile.exists());
|
||||
} else {
|
||||
@ -976,7 +976,7 @@ public class DatabaseGeneralTest extends AndroidTestCase implements PerformanceT
|
||||
memoryDb.close();
|
||||
assertFalse(memoryDb.isOpen());
|
||||
try {
|
||||
errorHandler.onCorruption(memoryDb);
|
||||
errorHandler.onCorruption(memoryDb, "");
|
||||
} catch (Exception e) {
|
||||
fail("unexpected");
|
||||
}
|
||||
@ -987,7 +987,7 @@ public class DatabaseGeneralTest extends AndroidTestCase implements PerformanceT
|
||||
assertNotNull(dbObj);
|
||||
assertTrue(dbObj.isOpen());
|
||||
try {
|
||||
errorHandler.onCorruption(dbObj);
|
||||
errorHandler.onCorruption(dbObj, "");
|
||||
if(SQLiteDatabase.hasCodec()){
|
||||
assertTrue(dbfile.exists());
|
||||
} else{
|
||||
@ -1012,7 +1012,7 @@ public class DatabaseGeneralTest extends AndroidTestCase implements PerformanceT
|
||||
assertTrue(dbObj.isOpen());
|
||||
List<Pair<String, String>> attachedDbs = dbObj.getAttachedDbs();
|
||||
try {
|
||||
errorHandler.onCorruption(dbObj);
|
||||
errorHandler.onCorruption(dbObj, "");
|
||||
if(SQLiteDatabase.hasCodec()){
|
||||
assertTrue(dbfile.exists());
|
||||
} else {
|
||||
@ -1047,7 +1047,7 @@ public class DatabaseGeneralTest extends AndroidTestCase implements PerformanceT
|
||||
assertTrue(dbObj.isOpen());
|
||||
attachedDbs = dbObj.getAttachedDbs();
|
||||
try {
|
||||
errorHandler.onCorruption(dbObj);
|
||||
errorHandler.onCorruption(dbObj, "");
|
||||
if(SQLiteDatabase.hasCodec()){
|
||||
assertTrue(dbfile.exists());
|
||||
} else {
|
||||
|
||||
@ -72,7 +72,7 @@ public class SQLCipherOpenHelperTest extends AndroidSQLCipherTestCase {
|
||||
private final String TAG = getClass().getSimpleName();
|
||||
|
||||
public SqlCipherOpenHelper(Context context) {
|
||||
super(context, "test.db", "test", null, 1, 1, sqLiteDatabase -> Log.e(SQLCipherOpenHelperTest.this.TAG, "onCorruption()"), new SQLiteDatabaseHook() {
|
||||
super(context, "test.db", "test", null, 1, 1, (sqLiteDatabase, message) -> Log.e(SQLCipherOpenHelperTest.this.TAG, "onCorruption()"), new SQLiteDatabaseHook() {
|
||||
@Override
|
||||
public void preKey(SQLiteConnection sqLiteConnection) {
|
||||
Log.d(SQLCipherOpenHelperTest.this.TAG, "preKey()");
|
||||
|
||||
@ -33,5 +33,5 @@ public interface DatabaseErrorHandler {
|
||||
* @param dbObj the {@link SQLiteDatabase} object representing the database on which corruption
|
||||
* is detected.
|
||||
*/
|
||||
void onCorruption(SQLiteDatabase dbObj);
|
||||
void onCorruption(SQLiteDatabase dbObj, String message);
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ public final class DefaultDatabaseErrorHandler implements DatabaseErrorHandler {
|
||||
* @param dbObj the {@link SQLiteDatabase} object representing the database on which corruption
|
||||
* is detected.
|
||||
*/
|
||||
public void onCorruption(SQLiteDatabase dbObj) {
|
||||
public void onCorruption(SQLiteDatabase dbObj, String message) {
|
||||
Log.e(TAG, "Corruption reported by sqlite on database: " + dbObj.getPath());
|
||||
|
||||
// If this is a SEE build, do not delete any database files.
|
||||
|
||||
@ -344,9 +344,9 @@ public final class SQLiteDatabase extends SQLiteClosable implements SupportSQLit
|
||||
/**
|
||||
* Sends a corruption message to the database error handler.
|
||||
*/
|
||||
void onCorruption() {
|
||||
void onCorruption(String message) {
|
||||
EventLog.writeEvent(EVENT_DB_CORRUPT, getLabel());
|
||||
mErrorHandler.onCorruption(this);
|
||||
mErrorHandler.onCorruption(this, message);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1013,7 +1013,7 @@ public final class SQLiteDatabase extends SQLiteClosable implements SupportSQLit
|
||||
try {
|
||||
openInner();
|
||||
} catch (SQLiteDatabaseCorruptException ex) {
|
||||
onCorruption();
|
||||
onCorruption(ex.getMessage());
|
||||
openInner();
|
||||
}
|
||||
} catch (SQLiteException ex) {
|
||||
|
||||
@ -113,8 +113,8 @@ public abstract class SQLiteProgram extends SQLiteClosable implements SupportSQL
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
protected final void onCorruption() {
|
||||
mDatabase.onCorruption();
|
||||
protected final void onCorruption(String message) {
|
||||
mDatabase.onCorruption(message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -68,7 +68,7 @@ public final class SQLiteQuery extends SQLiteProgram {
|
||||
mCancellationSignal);
|
||||
return numRows;
|
||||
} catch (SQLiteDatabaseCorruptException ex) {
|
||||
onCorruption();
|
||||
onCorruption(ex.getMessage());
|
||||
throw ex;
|
||||
} catch (SQLiteException ex) {
|
||||
Log.e(TAG, "exception: " + ex.getMessage() + "; query: " + getSql());
|
||||
|
||||
@ -49,7 +49,7 @@ public final class SQLiteStatement extends SQLiteProgram implements SupportSQLit
|
||||
try {
|
||||
getSession().execute(getSql(), getBindArgs(), getConnectionFlags(), null);
|
||||
} catch (SQLiteDatabaseCorruptException ex) {
|
||||
onCorruption();
|
||||
onCorruption(ex.getMessage());
|
||||
throw ex;
|
||||
} finally {
|
||||
releaseReference();
|
||||
@ -70,7 +70,7 @@ public final class SQLiteStatement extends SQLiteProgram implements SupportSQLit
|
||||
return getSession().executeForChangedRowCount(
|
||||
getSql(), getBindArgs(), getConnectionFlags(), null);
|
||||
} catch (SQLiteDatabaseCorruptException ex) {
|
||||
onCorruption();
|
||||
onCorruption(ex.getMessage());
|
||||
throw ex;
|
||||
} finally {
|
||||
releaseReference();
|
||||
@ -91,7 +91,7 @@ public final class SQLiteStatement extends SQLiteProgram implements SupportSQLit
|
||||
return getSession().executeForChangedRowCountRaw(
|
||||
getSql(), getBindArgs(), getConnectionFlags(), null);
|
||||
} catch (SQLiteDatabaseCorruptException ex) {
|
||||
onCorruption();
|
||||
onCorruption(ex.getMessage());
|
||||
throw ex;
|
||||
} finally {
|
||||
releaseReference();
|
||||
@ -113,7 +113,7 @@ public final class SQLiteStatement extends SQLiteProgram implements SupportSQLit
|
||||
return getSession().executeForLastInsertedRowId(
|
||||
getSql(), getBindArgs(), getConnectionFlags(), null);
|
||||
} catch (SQLiteDatabaseCorruptException ex) {
|
||||
onCorruption();
|
||||
onCorruption(ex.getMessage());
|
||||
throw ex;
|
||||
} finally {
|
||||
releaseReference();
|
||||
@ -134,7 +134,7 @@ public final class SQLiteStatement extends SQLiteProgram implements SupportSQLit
|
||||
return getSession().executeForLong(
|
||||
getSql(), getBindArgs(), getConnectionFlags(), null);
|
||||
} catch (SQLiteDatabaseCorruptException ex) {
|
||||
onCorruption();
|
||||
onCorruption(ex.getMessage());
|
||||
throw ex;
|
||||
} finally {
|
||||
releaseReference();
|
||||
@ -155,7 +155,7 @@ public final class SQLiteStatement extends SQLiteProgram implements SupportSQLit
|
||||
return getSession().executeForString(
|
||||
getSql(), getBindArgs(), getConnectionFlags(), null);
|
||||
} catch (SQLiteDatabaseCorruptException ex) {
|
||||
onCorruption();
|
||||
onCorruption(ex.getMessage());
|
||||
throw ex;
|
||||
} finally {
|
||||
releaseReference();
|
||||
@ -176,7 +176,7 @@ public final class SQLiteStatement extends SQLiteProgram implements SupportSQLit
|
||||
return getSession().executeForBlobFileDescriptor(
|
||||
getSql(), getBindArgs(), getConnectionFlags(), null);
|
||||
} catch (SQLiteDatabaseCorruptException ex) {
|
||||
onCorruption();
|
||||
onCorruption(ex.getMessage());
|
||||
throw ex;
|
||||
} finally {
|
||||
releaseReference();
|
||||
|
||||
@ -124,8 +124,12 @@ void throw_sqlite3_exception(JNIEnv* env, int errcode,
|
||||
|
||||
if (sqlite3Message) {
|
||||
char *zFullmsg = sqlite3_mprintf(
|
||||
"%s (code %d)%s%s", sqlite3Message, errcode,
|
||||
(message ? ": " : ""), (message ? message : "")
|
||||
"FullCode: %d | ErrorCode: %d | ExtendedErrorCode: %d | Message: %s | ExtraMessage: %s",
|
||||
errcode,
|
||||
errcode & 0xff,
|
||||
errcode >> 8,
|
||||
sqlite3Message,
|
||||
(message ? message : "null")
|
||||
);
|
||||
jniThrowException(env, exceptionClass, zFullmsg);
|
||||
sqlite3_free(zFullmsg);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user