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

Error stops execution #71

Closed
adius opened this issue Jan 6, 2015 · 3 comments
Closed

Error stops execution #71

adius opened this issue Jan 6, 2015 · 3 comments

Comments

@adius
Copy link

adius commented Jan 6, 2015

I have following function which returns a promise:

function getStats (filePath) {
    return new Promise(function (fulfill, reject) {
        fs.stat(filePath, function (error, stats) {
            if (error)
                reject(error)
            else
                fulfill(stats)
        })
    })
}

Unfortunately I forgot to require fs before.
The outcome was, that the execution of the code stopped when I used the promise later.
Is this the correct behavior and how am I supposed to catch the exception then?

@adius
Copy link
Author

adius commented Jan 6, 2015

Oh, just saw that #70 is basically the same…

@adius
Copy link
Author

adius commented Jan 6, 2015

The correct fix seems to be:

function getStats (filePath) {
    return new Promise(function (fulfill, reject) {
        try {
            fs.stat(filePath, function (error, stats) {
                if (error)
                    reject(error)
                else
                    fulfill(stats)
            })
        }
        catch (error) {
            reject(error)
        }
    })
}

@stefanpenner
Copy link
Owner

dupe of #70 the promise works correctly, but we should likely activate the extra logging in this project.

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

2 participants