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

src: move node::errno_string into node_errors.h/cc #25396

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ void Environment::CollectExceptionInfo(Local<Value> object,
return;

Local<Object> obj = object.As<Object>();
const char* err_string = node::errno_string(errorno);
const char* err_string = errors::errno_string(errorno);

if (message == nullptr || message[0] == '\0') {
message = strerror(errorno);
Expand Down
10 changes: 6 additions & 4 deletions src/exceptions.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "node.h"
#include "node_internals.h"
// This file contains implementation of error APIs exposed in node.h

#include "env-inl.h"
#include "node.h"
#include "node_errors.h"
#include "util-inl.h"
#include "v8.h"
#include "uv.h"
#include "v8.h"

#include <string.h>

Expand All @@ -27,7 +29,7 @@ Local<Value> ErrnoException(Isolate* isolate,
Environment* env = Environment::GetCurrent(isolate);

Local<Value> e;
Local<String> estring = OneByteString(isolate, errno_string(errorno));
Local<String> estring = OneByteString(isolate, errors::errno_string(errorno));
if (msg == nullptr || msg[0] == '\0') {
msg = strerror(errorno);
}
Expand Down
330 changes: 330 additions & 0 deletions src/node_errors.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <errno.h>
#include <stdarg.h>

#include "node_errors.h"
#include "node_internals.h"

Expand Down Expand Up @@ -326,6 +328,334 @@ TryCatchScope::~TryCatchScope() {
}
}

const char* errno_string(int errorno) {
#define ERRNO_CASE(e) \
case e: \
return #e;
switch (errorno) {
#ifdef EACCES
ERRNO_CASE(EACCES);
#endif

#ifdef EADDRINUSE
ERRNO_CASE(EADDRINUSE);
#endif

#ifdef EADDRNOTAVAIL
ERRNO_CASE(EADDRNOTAVAIL);
#endif

#ifdef EAFNOSUPPORT
ERRNO_CASE(EAFNOSUPPORT);
#endif

#ifdef EAGAIN
ERRNO_CASE(EAGAIN);
#endif

#ifdef EWOULDBLOCK
#if EAGAIN != EWOULDBLOCK
ERRNO_CASE(EWOULDBLOCK);
#endif
#endif

#ifdef EALREADY
ERRNO_CASE(EALREADY);
#endif

#ifdef EBADF
ERRNO_CASE(EBADF);
#endif

#ifdef EBADMSG
ERRNO_CASE(EBADMSG);
#endif

#ifdef EBUSY
ERRNO_CASE(EBUSY);
#endif

#ifdef ECANCELED
ERRNO_CASE(ECANCELED);
#endif

#ifdef ECHILD
ERRNO_CASE(ECHILD);
#endif

#ifdef ECONNABORTED
ERRNO_CASE(ECONNABORTED);
#endif

#ifdef ECONNREFUSED
ERRNO_CASE(ECONNREFUSED);
#endif

#ifdef ECONNRESET
ERRNO_CASE(ECONNRESET);
#endif

#ifdef EDEADLK
ERRNO_CASE(EDEADLK);
#endif

#ifdef EDESTADDRREQ
ERRNO_CASE(EDESTADDRREQ);
#endif

#ifdef EDOM
ERRNO_CASE(EDOM);
#endif

#ifdef EDQUOT
ERRNO_CASE(EDQUOT);
#endif

#ifdef EEXIST
ERRNO_CASE(EEXIST);
#endif

#ifdef EFAULT
ERRNO_CASE(EFAULT);
#endif

#ifdef EFBIG
ERRNO_CASE(EFBIG);
#endif

#ifdef EHOSTUNREACH
ERRNO_CASE(EHOSTUNREACH);
#endif

#ifdef EIDRM
ERRNO_CASE(EIDRM);
#endif

#ifdef EILSEQ
ERRNO_CASE(EILSEQ);
#endif

#ifdef EINPROGRESS
ERRNO_CASE(EINPROGRESS);
#endif

#ifdef EINTR
ERRNO_CASE(EINTR);
#endif

#ifdef EINVAL
ERRNO_CASE(EINVAL);
#endif

#ifdef EIO
ERRNO_CASE(EIO);
#endif

#ifdef EISCONN
ERRNO_CASE(EISCONN);
#endif

#ifdef EISDIR
ERRNO_CASE(EISDIR);
#endif

#ifdef ELOOP
ERRNO_CASE(ELOOP);
#endif

#ifdef EMFILE
ERRNO_CASE(EMFILE);
#endif

#ifdef EMLINK
ERRNO_CASE(EMLINK);
#endif

#ifdef EMSGSIZE
ERRNO_CASE(EMSGSIZE);
#endif

#ifdef EMULTIHOP
ERRNO_CASE(EMULTIHOP);
#endif

#ifdef ENAMETOOLONG
ERRNO_CASE(ENAMETOOLONG);
#endif

#ifdef ENETDOWN
ERRNO_CASE(ENETDOWN);
#endif

#ifdef ENETRESET
ERRNO_CASE(ENETRESET);
#endif

#ifdef ENETUNREACH
ERRNO_CASE(ENETUNREACH);
#endif

#ifdef ENFILE
ERRNO_CASE(ENFILE);
#endif

#ifdef ENOBUFS
ERRNO_CASE(ENOBUFS);
#endif

#ifdef ENODATA
ERRNO_CASE(ENODATA);
#endif

#ifdef ENODEV
ERRNO_CASE(ENODEV);
#endif

#ifdef ENOENT
ERRNO_CASE(ENOENT);
#endif

#ifdef ENOEXEC
ERRNO_CASE(ENOEXEC);
#endif

#ifdef ENOLINK
ERRNO_CASE(ENOLINK);
#endif

#ifdef ENOLCK
#if ENOLINK != ENOLCK
ERRNO_CASE(ENOLCK);
#endif
#endif

#ifdef ENOMEM
ERRNO_CASE(ENOMEM);
#endif

#ifdef ENOMSG
ERRNO_CASE(ENOMSG);
#endif

#ifdef ENOPROTOOPT
ERRNO_CASE(ENOPROTOOPT);
#endif

#ifdef ENOSPC
ERRNO_CASE(ENOSPC);
#endif

#ifdef ENOSR
ERRNO_CASE(ENOSR);
#endif

#ifdef ENOSTR
ERRNO_CASE(ENOSTR);
#endif

#ifdef ENOSYS
ERRNO_CASE(ENOSYS);
#endif

#ifdef ENOTCONN
ERRNO_CASE(ENOTCONN);
#endif

#ifdef ENOTDIR
ERRNO_CASE(ENOTDIR);
#endif

#ifdef ENOTEMPTY
#if ENOTEMPTY != EEXIST
ERRNO_CASE(ENOTEMPTY);
#endif
#endif

#ifdef ENOTSOCK
ERRNO_CASE(ENOTSOCK);
#endif

#ifdef ENOTSUP
ERRNO_CASE(ENOTSUP);
#else
#ifdef EOPNOTSUPP
ERRNO_CASE(EOPNOTSUPP);
#endif
#endif

#ifdef ENOTTY
ERRNO_CASE(ENOTTY);
#endif

#ifdef ENXIO
ERRNO_CASE(ENXIO);
#endif

#ifdef EOVERFLOW
ERRNO_CASE(EOVERFLOW);
#endif

#ifdef EPERM
ERRNO_CASE(EPERM);
#endif

#ifdef EPIPE
ERRNO_CASE(EPIPE);
#endif

#ifdef EPROTO
ERRNO_CASE(EPROTO);
#endif

#ifdef EPROTONOSUPPORT
ERRNO_CASE(EPROTONOSUPPORT);
#endif

#ifdef EPROTOTYPE
ERRNO_CASE(EPROTOTYPE);
#endif

#ifdef ERANGE
ERRNO_CASE(ERANGE);
#endif

#ifdef EROFS
ERRNO_CASE(EROFS);
#endif

#ifdef ESPIPE
ERRNO_CASE(ESPIPE);
#endif

#ifdef ESRCH
ERRNO_CASE(ESRCH);
#endif

#ifdef ESTALE
ERRNO_CASE(ESTALE);
#endif

#ifdef ETIME
ERRNO_CASE(ETIME);
#endif

#ifdef ETIMEDOUT
ERRNO_CASE(ETIMEDOUT);
#endif

#ifdef ETXTBSY
ERRNO_CASE(ETXTBSY);
#endif

#ifdef EXDEV
ERRNO_CASE(EXDEV);
#endif

default:
return "";
}
}

} // namespace errors

void DecorateErrorStack(Environment* env,
Expand Down
3 changes: 2 additions & 1 deletion src/node_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,12 @@ class TryCatchScope : public v8::TryCatch {
CatchMode mode_;
};

const char* errno_string(int errorno);

} // namespace errors

void DecorateErrorStack(Environment* env,
const errors::TryCatchScope& try_catch);

} // namespace node

#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
Expand Down
Loading