You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 2, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Dec 2, 2026. It is now read-only.
Provide error code when a function call has failed #1206
Running the code above will print out the output below if the two commits have no common ancestor.
[Error: No merge base found]
The error code behind this error is Error.CODE.ENOTFOUND but there is no way for a client to know this. Not having a common ancestor between two commits is an error that a client may be able to handle gracefully but if it the function failed because of some other fatal error then maybe the client can't do anything about it. Without an error code available in the catch callback, clients have no way of figuring out why the function failed outside of parsing the error message itself. It would be nice if we could have something like either of the two following patterns...
I couldn't figure out how to implement the first pattern with two arguments since the promise didn't seem to want to return two things. :(
I did get some code working that implements the second pattern though. I changed the error code's property name to be errno instead of code to match what was already used elsewhere in async_function.cc.
Are either of the following two proposed solutions acceptable?
If not, can anyone suggest an alternative solution that would be acceptable? Thanks!
Activity
rcjsuen commentedon Jan 30, 2017
I couldn't figure out how to implement the first pattern with two arguments since the promise didn't seem to want to return two things. :(
I did get some code working that implements the second pattern though. I changed the error code's property name to be
errnoinstead ofcodeto match what was already used elsewhere inasync_function.cc.Are either of the following two proposed solutions acceptable?
If not, can anyone suggest an alternative solution that would be acceptable? Thanks!
maxkorp commentedon Jan 30, 2017
I like the second proposal for sure.
CC: @johnhaley81 @tbranyen Any thoughts?
tbranyen commentedon Jan 30, 2017
In order to pass two values to a
thenyou'd have to resolve an array and then use destructuring:That said, I much prefer the second approach, except why is there
msg? Why can't you just attach theerrnodirectly to the error object?rcjsuen commentedon Jan 30, 2017
We can do that, @tbranyen. That is what is shown in the first example of my second comment.
rcjsuen commentedon Jan 31, 2017
I have pushed PR #1209 to expose the error code to NodeGit clients.
tbranyen commentedon Feb 10, 2017
Just wanted to leave this internal Node error code reference: https://github.com/nodejs/node/blob/master/doc/guides/using-internal-errors.md
rcjsuen commentedon Feb 28, 2017
Closing as PR #1209 has been merged in. Will be included in 0.18.0.