Bug 1407778 - Added status Error property on Sqlite.openConnection. r=mak

This commit is contained in:
Zack Noyes, William Loughton
2018-01-23 23:11:54 -08:00
parent 1c39f5bdcd
commit e6cc7fc296
4 changed files with 24 additions and 2 deletions

View File

@@ -945,7 +945,9 @@ function openConnection(options) {
Services.storage.openAsyncDatabase(file, dbOptions, (status, connection) => {
if (!connection) {
log.warn(`Could not open connection to ${path}: ${status}`);
reject(new Error(`Could not open connection to ${path}: ${status}`));
let error = new Error(`Could not open connection to ${path}: ${status}`);
error.status = status;
reject(error);
return;
}
log.info("Connection opened");

View File

@@ -0,0 +1 @@
CORRUPTED_SQLITE_FILE_CONTENTS

View File

@@ -1,6 +1,6 @@
"use strict";
var {classes: Cc, interfaces: Ci, utils: Cu} = Components;
var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
do_get_profile();
@@ -91,6 +91,24 @@ add_task(async function test_open_normal() {
await c.close();
});
add_task(async function test_open_normal_error() {
let currentDir = await OS.File.getCurrentDirectory();
let src = OS.Path.join(currentDir, "corrupt.sqlite");
Assert.ok((await OS.File.exists(src)), "Database file found");
// Ensure that our database doesn't already exist.
let path = OS.Path.join(OS.Constants.Path.profileDir, "corrupt.sqlite");
Assert.ok(!(await OS.File.exists(path)), "Database file should not exist yet");
await OS.File.copy(src, path);
let openPromise = Sqlite.openConnection({path});
await Assert.rejects(openPromise, reason => {
return reason.status == Cr.NS_ERROR_FILE_CORRUPTED;
}, "Check error status");
});
add_task(async function test_open_unshared() {
let path = OS.Path.join(OS.Constants.Path.profileDir, "test_open_unshared.sqlite");

View File

@@ -4,6 +4,7 @@ support-files =
propertyLists/bug710259_propertyListBinary.plist
propertyLists/bug710259_propertyListXML.plist
chromeappsstore.sqlite
corrupt.sqlite
zips/zen.zip
[test_BinarySearch.js]