Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Throw HumanReadableException when initializing SQLite fails
Browse files Browse the repository at this point in the history
Summary:
Hopefully this is the last time I have to twiddle this error handling
path... the existing solution had a couple minor irritations: (1) the failure
showed up as a NoClassDefFound exception, which hides the real root cause, and
(2) throwing it as a RuntimeException pollutes logging and the user's console.

So, we'll tweak this slightly to use a synchronized static method instead of a
static initializer, and throw a nice pretty HumanReadableException.  Since most
of the time this error is caused by not having space for the .so, I'll even
suggest that the user may be low on disk space.

Test Plan:
mount buck-out/tmp on a tiny volume to trigger the error:
```
BUILD FAILED: Failed to initialize sqlite-jdbc.  Is your disk full?
```

Reviewed By: dinhviethoa

fbshipit-source-id: fa0ca96
  • Loading branch information
bertmaher authored and facebook-github-bot committed Jul 21, 2017
1 parent 0fd0bec commit ce7979b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
5 changes: 1 addition & 4 deletions src/com/facebook/buck/rules/SQLiteBuildInfoStore.java
Expand Up @@ -36,11 +36,8 @@ public class SQLiteBuildInfoStore implements BuildInfoStore {
private final PreparedStatement updateStmt;
private final PreparedStatement deleteStmt;

static {
SQLiteUtils.initialize();
}

public SQLiteBuildInfoStore(ProjectFilesystem filesystem) throws IOException {
SQLiteUtils.initialize();
String dbPath =
filesystem
.getRootPath()
Expand Down
1 change: 1 addition & 0 deletions src/com/facebook/buck/sqlite/BUCK
Expand Up @@ -3,6 +3,7 @@ java_library(
srcs = glob(["*.java"]),
visibility = ["PUBLIC"],
deps = [
"//src/com/facebook/buck/util:exceptions",
"//third-party/java/sqlite:sqlite",
],
)
13 changes: 9 additions & 4 deletions src/com/facebook/buck/sqlite/SQLiteUtils.java
Expand Up @@ -16,6 +16,7 @@

package com.facebook.buck.sqlite;

import com.facebook.buck.util.HumanReadableException;
import org.sqlite.SQLiteJDBCLoader;

public class SQLiteUtils {
Expand All @@ -28,13 +29,17 @@ private SQLiteUtils() {
* thread-unsafe manner. This method should be called statically from any class that uses
* SQLiteJDBC.
*/
public static void initialize() {
public static synchronized void initialize() {
boolean success;
try {
if (!SQLiteJDBCLoader.initialize()) {
throw new RuntimeException("sqlite-jdbc initialization failed");
}
success = SQLiteJDBCLoader.initialize();
} catch (Exception e) {
throw new RuntimeException(e);
}
if (!success) {
throw new HumanReadableException(
"Failed to initialize Buck (sqlite-jdbc). A common reason is that the disk is full. "
+ "Please try to clean up your disk and try again.");
}
}
}

0 comments on commit ce7979b

Please sign in to comment.