summaryrefslogtreecommitdiff
path: root/ext/cache/sqlite.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-11-08 12:27:29 +0530
committerGitHub <noreply@github.com>2024-11-08 12:27:29 +0530
commit637b1d5508293ed02bef2f317b30bb7c1f0cbc71 (patch)
treedc241424a5f54cd8ce56c0aaa0d11f27e3a09ddf /ext/cache/sqlite.rs
parentbf82c6697a9cb734998ceaa3f45768c3d8bd79b7 (diff)
fix(ext/cache): don't panic when creating cache (#26780)
Diffstat (limited to 'ext/cache/sqlite.rs')
-rw-r--r--ext/cache/sqlite.rs23
1 files changed, 9 insertions, 14 deletions
diff --git a/ext/cache/sqlite.rs b/ext/cache/sqlite.rs
index e4991c32f..6efceda11 100644
--- a/ext/cache/sqlite.rs
+++ b/ext/cache/sqlite.rs
@@ -42,7 +42,7 @@ pub struct SqliteBackedCache {
}
impl SqliteBackedCache {
- pub fn new(cache_storage_dir: PathBuf) -> Self {
+ pub fn new(cache_storage_dir: PathBuf) -> Result<Self, CacheError> {
{
std::fs::create_dir_all(&cache_storage_dir)
.expect("failed to create cache dir");
@@ -57,18 +57,14 @@ impl SqliteBackedCache {
PRAGMA synchronous=NORMAL;
PRAGMA optimize;
";
- connection
- .execute_batch(initial_pragmas)
- .expect("failed to execute pragmas");
- connection
- .execute(
- "CREATE TABLE IF NOT EXISTS cache_storage (
+ connection.execute_batch(initial_pragmas)?;
+ connection.execute(
+ "CREATE TABLE IF NOT EXISTS cache_storage (
id INTEGER PRIMARY KEY,
cache_name TEXT NOT NULL UNIQUE
)",
- (),
- )
- .expect("failed to create cache_storage table");
+ (),
+ )?;
connection
.execute(
"CREATE TABLE IF NOT EXISTS request_response_list (
@@ -86,12 +82,11 @@ impl SqliteBackedCache {
UNIQUE (cache_id, request_url)
)",
(),
- )
- .expect("failed to create request_response_list table");
- SqliteBackedCache {
+ )?;
+ Ok(SqliteBackedCache {
connection: Arc::new(Mutex::new(connection)),
cache_storage_dir,
- }
+ })
}
}
}