core: Make errno message a part of errno exceptions #2695

Closed
wants to merge 10 commits into
from

Conversation

Projects
None yet
4 participants
Member

AndreasMadsen commented Feb 4, 2012

To people like me there don't use enough time with errno codes it can be difficult to remember what EBADF means. This add a text message to all errno exceptions, like bad file descriptor.

The messages are from get_uv_errno_message, to use this it was necessary to change the SetError so it set errno to a number and not get_uv_errno_string.

I'm hoping we later could abstract ErrnoException from node.cc to use Errno::ErrnoException.

It would also be nice to have binding functions return an uv_errno number instead of 1 or 0. This way we won't pollute global scope with errno.

Example of this patch:

var Pipe = process.binding('pipe_wrap').Pipe;
var errnoException = process.binding('errno').errnoException;

var stream = new Pipe(true);
    stream.close();

var buffer = new Buffer("test");
var errno = stream.write(buffer, 0, buffer.length);
if (errno !== 0) {
  throw errnoException(errno, 'write');
}

@piscisaureus told me that you did not want any errno changes now, but since I had made the patch why not allow you to reconsider.

Owner

bnoordhuis commented Feb 4, 2012

It would also be nice to have binding functions return an uv_errno number instead of 1 or 0. This way we won't pollute global scope with errno. Example of this:

Agreed. We could (and probably should) copy the Linux kernel convention here: return >=0 on succes, -ERRNUM on error.

Can one of the admins verify this patch?

This work has been done in libuv and in node, in various commits. libuv now directly returns the errno and we map that to a useful value and include the syscall

tjfontaine closed this Feb 18, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment