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

Unhandled Rejection Error #9

Open
codinfox opened this issue May 12, 2015 · 2 comments
Open

Unhandled Rejection Error #9

codinfox opened this issue May 12, 2015 · 2 comments
Assignees

Comments

@codinfox
Copy link

This issue is about the demo of promise.

It seems that https://github.com/rethinkdb/rethinkdb-example-nodejs/blob/master/todo-angular-express-promise/app.js#L135 and https://github.com/rethinkdb/rethinkdb-example-nodejs/blob/master/todo-angular-express-promise/app.js#L137 can be rejected and since they are not handled by any .error() clause, it is likely to throw an error. I think the right way to do is:

...
        }).finally(function() {
            return r.table('todos').indexCreate('createdAt').run(conn);
        }).finally(function(result) {
            return r.table('todos').indexWait('createdAt').run(conn)
        }).then(function(result) {
...

Or, are these codes written this way on specific purposes?

@danielmewes
Copy link
Member

Good catch @codinfox . It doesn't look like it's intentional to me (though I could be wrong).

@deontologician is currently out of office, but he will look into it when he's back.

@codinfox
Copy link
Author

Thanks, @danielmewes !
I think what we really care about is just the run result of the last finally (whether indexWait resolved or rejected). So I think the code should be something like:

...
            r.table(dbConn.TABLE_NAME).indexWait(dbConn.INDEX_NAME).run(conn).then(function(){
                conn.close();
                successCallback();
            }).error(function() {
                console.log('Setting up database...');
                // The database/table/index was not available, create them
                r.dbCreate(dbConn.DATABASE_NAME).run(conn).finally(function() {
                    return r.tableCreate(dbConn.TABLE_NAME).run(conn);
                }).finally(function() {
                    return r.table(dbConn.TABLE_NAME).indexCreate(dbConn.INDEX_NAME).run(conn);
                }).catch(function(){})/*We swallow the results of the above promises*/.finally(function() {
                    return r.table(dbConn.TABLE_NAME).indexWait(dbConn.INDEX_NAME).run(conn);
                }).then(successCallback).error(function(err) {
                    console.log('Could not wait for the completion of indexing.')
                    console.log(err.message);
                    process.exit(1);
                }).finally(conn.close);
            });
...

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

No branches or pull requests

3 participants