Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to execute 'index' on 'IDBObjectStore': The specified index was not found. #30

Open
neslinesli93 opened this issue May 5, 2015 · 5 comments
Labels

Comments

@neslinesli93
Copy link

In my code I have a function like that:

findOneByIndex: function(entityName, id, index) {
    var d = $q.defer();
    var promise = d.promise;

    $indexedDB.openStore(entityName, function(table) {
        table.findWhere(table.query().$index(index).$eq(id)).then(function(result) {
            if (result.length === 0) {
                console.log('No objects found');
                return d.reject(result);
            } else {
                return d.resolve(result[0]);
            }
        }, function(error) {
            console.log(error);
        });
    }, 'readwrite').then(null, function(error) {
        console.log(error);
    });

    return promise;
}

If I try to query IDB with an index that does not exist, I would expect the exception gets caught and logged. The problem is when I try to test this behaviour, I get:

  Uncaught NotFoundError: Failed to execute 'index' on 'IDBObjectStore': The specified index was not found.
  at angular-mocks/angular-mocks.js:9

I was wondering if it's a problem with angular mocks or with angular-indexedDB.
In my test I am injecting $indexedDB

@bramski
Copy link
Owner

bramski commented May 5, 2015

I'm on extended vacation right now and may get back to looking at this in a
week. You lack .catch on your useage of promises here.

The "uncaught" is from an exception being thrown in promise handling and
there being no catch in place to handle it.

I'm fairly certain the error is in your code though and I'm not able to
help you out. If you do find a solution and it turns out to be a problem
with the lib, make a repro and submit a PR if you can.

Best of luck.
On May 5, 2015 7:07 AM, "Tom Pom" [email protected] wrote:

In my code I have a function like that:

findOneByIndex: function(entityName, id, index) {
var d = $q.defer();
var promise = d.promise;

$indexedDB.openStore(entityName, function(table) {
    table.findWhere(table.query().$index(index).$eq(id)).then(function(result) {
        if (result.length === 0) {
            console.log('No objects found');
            return d.reject(result);
        } else {
            return d.resolve(result[0]);
        }
    }, function(error) {
        console.log(error);
    });
}, 'readwrite').then(null, function(error) {
    console.log(error);
});

return promise;

}

If I try to query IDB with an index that does not exist, I would expect
the exception gets caught and logged. The problem is when I try to test
this behaviour, I get:

Uncaught NotFoundError: Failed to execute 'index' on 'IDBObjectStore': The specified index was not found.
at angular-mocks/angular-mocks.js:9

I was wondering if it's a problem with angular mocks or with
angular-indexedDB.
In my test I am injecting $indexedDB


Reply to this email directly or view it on GitHub
#30.

@neslinesli93
Copy link
Author

Could you be more precise on where .catch is missing? Because from the Angular documentation

promise.catch(errorCallback)

is a shortand for

promise.then(null, errorCallback)

I tried to use the function findBy(index, id) instead of findWhere(), but the result is the same. My point is: shouldn't the error be handled inside the library, in the form of a promise being rejected?
For example, if you try to call openStore() on a non existing database, the promise is rejected and the error is handled correctly as well.
Looking at angular-indexedDB code, all the functions that take an index as a parameter do not check the integrity of it and they concatenate other functions call assuming the index is correct.

@neslinesli93
Copy link
Author

Okay I've looked at the code a bit more in depth and I can try to submit a pr in the next days.
It's just about checking if the index provided by the user is inside IDBObjectStore.indexNames, and it addresses the functions findBy() and eachWhere().

@bramski bramski added the bug label Jun 7, 2015
@bramski
Copy link
Owner

bramski commented Jun 7, 2015

Feel free.

@neslinesli93
Copy link
Author

Oh well, I tried and failed.
The core problem was that i was trying to put two transactions inside one function, and it was always complaining about "$digest being already in progress" or something like that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants