Bug 597400: return null if GUID lookup fails in forms engine. r=philiKON

This commit is contained in:
Richard Newman 2011-01-06 12:05:30 -08:00
Родитель c9a23f8fc5
Коммит e606392d85
2 изменённых файлов: 20 добавлений и 0 удалений

Просмотреть файл

@ -46,8 +46,11 @@ Cu.import("resource://services-sync/stores.js");
Cu.import("resource://services-sync/trackers.js");
Cu.import("resource://services-sync/type_records/forms.js");
Cu.import("resource://services-sync/util.js");
Cu.import("resource://services-sync/log4moz.js");
let FormWrapper = {
_log: Log4Moz.repository.getLogger('Engine.Forms'),
getAllEntries: function getAllEntries() {
// Sort by (lastUsed - minLast) / (maxLast - minLast) * timesUsed / maxTimes
let query = this.createStatement(
@ -76,6 +79,16 @@ let FormWrapper = {
// Give the guid if we found one
let item = Utils.queryAsync(getQuery, "guid")[0];
if (!item) {
// Shouldn't happen, but Bug 597400...
// Might as well just return.
this._log.warn("GUID query returned " + item + "; turn on Trace logging for details.");
this._log.trace("getGUID(" + JSON.stringify(name) + ", " +
JSON.stringify(value) + ") => " + item);
return null;
}
if (item.guid != null)
return item.guid;

Просмотреть файл

@ -1,10 +1,12 @@
Cu.import("resource://services-sync/engines/forms.js");
Cu.import("resource://services-sync/util.js");
Cu.import("resource://services-sync/log4moz.js");
function run_test() {
_("Verify we've got an empty tracker to work with.");
let tracker = new FormEngine()._tracker;
do_check_eq([id for (id in tracker.changedIDs)].length, 0);
Log4Moz.repository.rootLogger.addAppender(new Log4Moz.DumpAppender());
try {
_("Create an entry. Won't show because we haven't started tracking yet");
@ -32,6 +34,11 @@ function run_test() {
Svc.Obs.notify("weave:engine:stop-tracking");
Svc.Form.removeEntry("email", "john@doe.com");
do_check_eq([id for (id in tracker.changedIDs)].length, 0);
_("Test error detection.");
// This throws an exception without the fix for Bug 597400.
tracker.trackEntry("foo", "bar");
} finally {
_("Clean up.");
Svc.Form.removeAllEntries();