Bug 1149815 - Pass storage function failure codes through to callers, r=asuth.

This commit is contained in:
Ben Turner 2015-06-20 09:08:20 -07:00
parent b257e4061b
commit 89bd61a5bb
2 changed files with 50 additions and 5 deletions

View File

@ -107,6 +107,7 @@ EXPORTS
sqlite3_result_double
sqlite3_result_error
sqlite3_result_error16
sqlite3_result_error_code
sqlite3_result_error_nomem
sqlite3_result_int
sqlite3_result_int64

View File

@ -17,6 +17,7 @@
#include "mozilla/Mutex.h"
#include "mozilla/CondVar.h"
#include "mozilla/Attributes.h"
#include "mozilla/ErrorNames.h"
#include "mozIStorageAggregateFunction.h"
#include "mozIStorageCompletionCallback.h"
@ -67,6 +68,43 @@ namespace storage {
namespace {
int
nsresultToSQLiteResult(nsresult aXPCOMResultCode)
{
if (NS_SUCCEEDED(aXPCOMResultCode)) {
return SQLITE_OK;
}
switch (aXPCOMResultCode) {
case NS_ERROR_FILE_CORRUPTED:
return SQLITE_CORRUPT;
case NS_ERROR_FILE_ACCESS_DENIED:
return SQLITE_CANTOPEN;
case NS_ERROR_STORAGE_BUSY:
return SQLITE_BUSY;
case NS_ERROR_FILE_IS_LOCKED:
return SQLITE_LOCKED;
case NS_ERROR_FILE_READ_ONLY:
return SQLITE_READONLY;
case NS_ERROR_STORAGE_IOERR:
return SQLITE_IOERR;
case NS_ERROR_FILE_NO_DEVICE_SPACE:
return SQLITE_FULL;
case NS_ERROR_OUT_OF_MEMORY:
return SQLITE_NOMEM;
case NS_ERROR_UNEXPECTED:
return SQLITE_MISUSE;
case NS_ERROR_ABORT:
return SQLITE_ABORT;
case NS_ERROR_STORAGE_CONSTRAINT:
return SQLITE_CONSTRAINT;
default:
return SQLITE_ERROR;
}
MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Must return in switch above!");
}
////////////////////////////////////////////////////////////////////////////////
//// Variant Specialization Functions (variantToSQLiteT)
@ -212,11 +250,17 @@ basicFunctionHelper(sqlite3_context *aCtx,
return;
nsCOMPtr<nsIVariant> result;
if (NS_FAILED(func->OnFunctionCall(arguments, getter_AddRefs(result)))) {
NS_WARNING("User function returned error code!");
::sqlite3_result_error(aCtx,
"User function returned error code",
-1);
nsresult rv = func->OnFunctionCall(arguments, getter_AddRefs(result));
if (NS_FAILED(rv)) {
nsAutoCString errorMessage;
GetErrorName(rv, errorMessage);
errorMessage.InsertLiteral("User function returned ", 0);
errorMessage.Append('!');
NS_WARNING(errorMessage.get());
::sqlite3_result_error(aCtx, errorMessage.get(), -1);
::sqlite3_result_error_code(aCtx, nsresultToSQLiteResult(rv));
return;
}
int retcode = variantToSQLiteT(aCtx, result);