Giter Club home page Giter Club logo

Comments (5)

bramski avatar bramski commented on August 26, 2024

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.

from angular-indexeddb.

neslinesli93 avatar neslinesli93 commented on August 26, 2024

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.

from angular-indexeddb.

neslinesli93 avatar neslinesli93 commented on August 26, 2024

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().

from angular-indexeddb.

bramski avatar bramski commented on August 26, 2024

Feel free.

from angular-indexeddb.

neslinesli93 avatar neslinesli93 commented on August 26, 2024

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

from angular-indexeddb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.