diff --git a/src/env.cc b/src/env.cc index fa8cc0d1addfd7..8ef00a229c268d 100644 --- a/src/env.cc +++ b/src/env.cc @@ -27,7 +27,7 @@ void Environment::PrintSyncTrace() const { Local stack = StackTrace::CurrentStackTrace(isolate(), 10, StackTrace::kDetailed); - fprintf(stderr, "(node:%d) WARNING: Detected use of sync API\n", getpid()); + fprintf(stderr, STR_SYNC_WARNING, getpid()); for (int i = 0; i < stack->GetFrameCount() - 1; i++) { Local stack_frame = stack->GetFrame(i); @@ -38,10 +38,10 @@ void Environment::PrintSyncTrace() const { if (stack_frame->IsEval()) { if (stack_frame->GetScriptId() == Message::kNoScriptIdInfo) { - fprintf(stderr, " at [eval]:%i:%i\n", line_number, column); + fprintf(stderr, " " STR_AT " [eval]:%i:%i\n", line_number, column); } else { fprintf(stderr, - " at [eval] (%s:%i:%i)\n", + " " STR_AT " [eval] (%s:%i:%i)\n", *script_name, line_number, column); @@ -50,10 +50,11 @@ void Environment::PrintSyncTrace() const { } if (fn_name_s.length() == 0) { - fprintf(stderr, " at %s:%i:%i\n", *script_name, line_number, column); + fprintf(stderr, " " STR_AT " %s:%i:%i\n", + *script_name, line_number, column); } else { fprintf(stderr, - " at %s (%s:%i:%i)\n", + " " STR_AT " %s (%s:%i:%i)\n", *fn_name_s, *script_name, line_number, diff --git a/src/messages/en/messages.h b/src/messages/en/messages.h index 547f254bf8436b..5b9d88969710cb 100644 --- a/src/messages/en/messages.h +++ b/src/messages/en/messages.h @@ -1,65 +1,137 @@ #ifndef SRC_NODE_MESSAGES_SRC_H_ #define SRC_NODE_MESSAGES_SRC_H_ +// node --help output + +#if HAVE_OPENSSL +#define NODE_HELP_OPENSSL \ + " --tls-cipher-list=val use an alternative default TLS cipher list\n" +#else // !HAVE_OPENSSL +#define NODE_HELP_OPENSSL "" +#endif // HAVE_OPENSSL + +#if defined(NODE_HAVE_I18N_SUPPORT) +#if !defined(NODE_HAVE_SMALL_ICU) +#define NODE_HELP_I18N_SMALL_ICU \ + " note: linked-in ICU data is\n" \ + " present.\n" +#else // defined(NODE_HAVE_SMALL_ICU) +#define NODE_HELP_I18N_SMALL_ICU "" +#endif // !defined(NODE_HAVE_SMALL_ICU) +#define NODE_HELP_I18N \ + " --icu-data-dir=dir set ICU data load path to dir\n" \ + " (overrides NODE_ICU_DATA)\n" \ + NODE_HELP_I18N_SMALL_ICU + +#define NODE_HELP_ICU_DATA \ + "NODE_ICU_DATA data path for ICU (Intl object) data\n" \ + " (will extend linked-in data)\n" + +#else // !defined(NODE_HAVE_I18N_SUPPORT) +#define NODE_HELP_ICU_DATA "" +#define NODE_HELP_I18N "" +#endif // defined(NODE_HAVE_I18N_SUPPORT) + +// Determine the path separator +#ifdef _WIN32 +#define NODE_HELP_SEP ";" +#else +#define NODE_HELP_SEP ":" +#endif + +#define STR_NODEHELP \ +"Usage: node [options] [ -e script | script.js ] [arguments] \n" \ + " node debug script.js [arguments] \n" \ + "\n" \ + "Options:\n" \ + " -v, --version print Node.js version\n" \ + " -e, --eval script evaluate script\n" \ + " -p, --print evaluate script and print result\n" \ + " -c, --check syntax check script without executing\n" \ + " -i, --interactive always enter the REPL even if stdin\n" \ + " does not appear to be a terminal\n" \ + " -r, --require module to preload (option can be repeated)\n" \ + " --no-deprecation silence deprecation warnings\n" \ + " --throw-deprecation throw an exception anytime a deprecated " \ + "function is used\n" \ + " --trace-deprecation show stack traces on deprecations\n" \ + " --trace-sync-io show stack trace when use of sync IO\n" \ + " is detected after the first tick\n" \ + " --track-heap-objects track heap object allocations for heap " \ + "snapshots\n" \ + " --prof-process process v8 profiler output generated\n" \ + " using --prof\n" \ + " --v8-options print v8 command line options\n" \ + NODE_HELP_OPENSSL \ + NODE_HELP_I18N \ + "\n" \ + "Environment variables:\n" \ + "NODE_PATH '" NODE_HELP_SEP "'-separated list of " \ + "directories\n" \ + " prefixed to the module search path.\n" \ + "NODE_DISABLE_COLORS set to 1 to disable colors in the REPL\n" \ + NODE_HELP_ICU_DATA \ + "NODE_REPL_HISTORY path to the persistent REPL history file\n" \ + "\n" \ + "Documentation can be found at https://nodejs.org/\n" + +// Other messages ... + #define NODE_MESSAGE_UNKNOWN "(Message Unknown)" #define NODE_DEPRECATE_MESSAGE(what, alternate) \ what " is deprecated. Use " alternate " instead." +#define STR_SYNC_WARNING "(node:%d) WARNING: Detected use of sync API\n" +#define STR_AT "at" +#define STR_OPENSSL_FIPS_FAIL "openssl fips failed: %s\n" +#define STR_PROCESS_TICKDOMAIN_NONFUNCTION \ + "process._tickDomainCallback assigned to non-function\n" +#define STR_RAW_ENCODING_REMOVED \ + "'raw' encoding (array of integers) has been removed. Use 'binary'.\n" +#define STR_MODULE_VERSION_MISMATCH \ + "Module version mismatch. Expected %d, got %d." +#define STR_BINDING "Binding %s" +#define STR_NO_SUCH_MODULE "No such module: %s" +#define STR_NO_SUCH_MODULE_LINKED "No such module was linked: %s" +#define STR_DEBUGPORT_OUTOFRANGE "Debug port must be in range 1024 to 65535.\n" +#define STR_REQUIRES_ARGUMENT "%s: %s requires an argument\n" +#define STR_START_DEBUGGER_FAIL "Starting debugger on port %d failed\n" +#define STR_START_DEBUGGER_AGENT "Starting debugger agent.\n" +#define STR_BAD_OPTION "bad option" + // The messages used in src/*.cc // These are used only within the Node.js native source #define STR_CONVERT_ARGS_TO_UTF8_FAIL "Could not convert arguments to utf8." #define STR_OUTOFMEMORY "Out of memory" -#define STR_CALLBACK_NOT_ASSIGNED \ - "init callback is not assigned to a function" -#define STR_HOOKSSHOULDNOTBESET \ - "hooks should not be set while also enabled" -#define STR_INITCALLBACK \ - "init callback must be a function" -#define STR_INVALID_FILENAME \ - "filename must be a valid string" -#define STR_INDEX_OUT_OF_RANGE \ - "out of range index" -#define STR_ARGUMENT_BUFFER \ - "argument should be a Buffer" -#define STR_ARGUMENT_STRING \ - "Argument must be a string" -#define STR_ARGUMENT_ARRAYBUFFER \ - "argument is not an ArrayBuffer" -#define STR_UNABLE_TO_SET_PROTOTYPE \ - "Unable to set Object prototype" -#define STR_INVALID_HEX \ - "Invalid hex string" -#define STR_OFFSET_OUTOFBOUNDS \ - "Offset is out of bounds" -#define STR_LENGTH_OUTOFBOUNDS \ - "length out of bounds" -#define STR_SANDBOX_OBJECT \ - "sandbox argument must be an object." -#define STR_VMSCRIPT_AS_CONSTRUCTOR \ - "Must call vm.Script as a constructor." -#define STR_CONTEXTIFIED_MUST_BE_OBJECT \ +#define STR_CALLBACK_NOT_ASSIGNED "init callback is not assigned to a function" +#define STR_HOOKSSHOULDNOTBESET "hooks should not be set while also enabled" +#define STR_INITCALLBACK "init callback must be a function" +#define STR_INVALID_FILENAME "filename must be a valid string" +#define STR_INDEX_OUT_OF_RANGE "out of range index" +#define STR_ARGUMENT_BUFFER "argument should be a Buffer" +#define STR_ARGUMENT_STRING "Argument must be a string" +#define STR_ARGUMENT_ARRAYBUFFER "argument is not an ArrayBuffer" +#define STR_UNABLE_TO_SET_PROTOTYPE "Unable to set Object prototype" +#define STR_INVALID_HEX "Invalid hex string" +#define STR_OFFSET_OUTOFBOUNDS "Offset is out of bounds" +#define STR_LENGTH_OUTOFBOUNDS "length out of bounds" +#define STR_SANDBOX_OBJECT "sandbox argument must be an object." +#define STR_VMSCRIPT_AS_CONSTRUCTOR "Must call vm.Script as a constructor." +#define STR_CONTEXTIFIED_MUST_BE_OBJECT \ "contextifiedSandbox argument must be an object." -#define STR_SANDBOX_ARGUMENT_CONVERSION \ +#define STR_SANDBOX_ARGUMENT_CONVERSION \ "sandbox argument must have been converted to a context." -#define STR_OPTIONS_OBJECT \ - "options must be an object" -#define STR_TIMEOUT_POSITIVE \ - "timeout must be a positive number" -#define STR_CANNOT_CALL_SCRIPT_METHODS \ +#define STR_OPTIONS_OBJECT "options must be an object" +#define STR_TIMEOUT_POSITIVE "timeout must be a positive number" +#define STR_CANNOT_CALL_SCRIPT_METHODS \ "Script methods can only be called on script instances." -#define STR_SCRIPT_EXECUTION_TIMEDOUT \ - "Script execution timed out." -#define STR_NOT_STRING_BUFFER \ - "Not a string or buffer" -#define STR_NOT_BUFFER \ - "Not a buffer" -#define STR_SSLV2_METHODS_DISABLED \ - "SSLv2 methods disabled" -#define STR_SSLV3_METHODS_DISABLED \ - "SSLv3 methods disabled" -#define STR_UNKNOWN_METHOD \ - "Unknown method" +#define STR_SCRIPT_EXECUTION_TIMEDOUT "Script execution timed out." +#define STR_NOT_STRING_BUFFER "Not a string or buffer" +#define STR_NOT_BUFFER "Not a buffer" +#define STR_SSLV2_METHODS_DISABLED "SSLv2 methods disabled" +#define STR_SSLV3_METHODS_DISABLED "SSLv3 methods disabled" +#define STR_UNKNOWN_METHOD "Unknown method" #define STR_BAD_PARAMETER "Bad parameter" #define STR_PEM_READ_BIO "PEM_read_bio_PrivateKey" #define STR_CTX_USE_PRIVATEKEY "SSL_CTX_use_PrivateKey" @@ -694,8 +766,7 @@ "directory. This functionality is deprecated and will be removed soon.") \ XX(MODULE_REQUIREREPL_DEPRECATED, "Module.requireRepl is deprecated.") \ XX(NET_SERVER_CONNECTIONS_DEPRECATED, \ - NODE_DEPRECATE_MESSAGE("Server.connections", \ - "Server.getConnections")) \ + NODE_DEPRECATE_MESSAGE("Server.connections", "Server.getConnections")) \ XX(NET_SERVER_CONNECTIONS_DEPRECATED_SET, \ "Server.connections property is deprecated.") \ XX(NET_SERVER_LISTENFD_DEPRECATED, \ diff --git a/src/node.cc b/src/node.cc index 6aa52ded929eaa..460bb5e5643afc 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1063,7 +1063,7 @@ void SetupDomainUse(const FunctionCallbackInfo& args) { process_object->Get(tick_callback_function_key).As(); if (!tick_callback_function->IsFunction()) { - fprintf(stderr, "process._tickDomainCallback assigned to non-function\n"); + fprintf(stderr, STR_PROCESS_TICKDOMAIN_NONFUNCTION); ABORT(); } @@ -1417,8 +1417,7 @@ ssize_t DecodeBytes(Isolate* isolate, HandleScope scope(isolate); if (val->IsArray()) { - fprintf(stderr, "'raw' encoding (array of integers) has been removed. " - "Use 'binary'.\n"); + fprintf(stderr, STR_RAW_ENCODING_REMOVED); UNREACHABLE(); return -1; } @@ -2277,7 +2276,7 @@ void DLOpen(const FunctionCallbackInfo& args) { char errmsg[1024]; snprintf(errmsg, sizeof(errmsg), - "Module version mismatch. Expected %d, got %d.", + STR_MODULE_VERSION_MISMATCH, NODE_MODULE_VERSION, mp->nm_version); // NOTE: `mp` is allocated inside of the shared library's memory, calling @@ -2404,7 +2403,7 @@ static void Binding(const FunctionCallbackInfo& args) { // Append a string to process.moduleLoadList char buf[1024]; - snprintf(buf, sizeof(buf), "Binding %s", *module_v); + snprintf(buf, sizeof(buf), STR_BINDING, *module_v); Local modules = env->module_load_list_array(); uint32_t l = modules->Length(); @@ -2436,7 +2435,7 @@ static void Binding(const FunctionCallbackInfo& args) { char errmsg[1024]; snprintf(errmsg, sizeof(errmsg), - "No such module: %s", + STR_NO_SUCH_MODULE, *module_v); return env->ThrowError(errmsg); } @@ -2462,7 +2461,7 @@ static void LinkedBinding(const FunctionCallbackInfo& args) { char errmsg[1024]; snprintf(errmsg, sizeof(errmsg), - "No such module was linked: %s", + STR_NO_SUCH_MODULE_LINKED, *module_v); return env->ThrowError(errmsg); } @@ -3268,7 +3267,7 @@ static bool ParseDebugOpt(const char* arg) { if (port != nullptr) { debug_port = atoi(port); if (debug_port < 1024 || debug_port > 65535) { - fprintf(stderr, "Debug port must be in range 1024 to 65535.\n"); + fprintf(stderr, STR_DEBUGPORT_OUTOFRANGE); PrintHelp(); exit(12); } @@ -3278,57 +3277,7 @@ static bool ParseDebugOpt(const char* arg) { } static void PrintHelp() { - printf("Usage: node [options] [ -e script | script.js ] [arguments] \n" - " node debug script.js [arguments] \n" - "\n" - "Options:\n" - " -v, --version print Node.js version\n" - " -e, --eval script evaluate script\n" - " -p, --print evaluate script and print result\n" - " -c, --check syntax check script without executing\n" - " -i, --interactive always enter the REPL even if stdin\n" - " does not appear to be a terminal\n" - " -r, --require module to preload (option can be repeated)\n" - " --no-deprecation silence deprecation warnings\n" - " --throw-deprecation throw an exception anytime a deprecated " - "function is used\n" - " --trace-deprecation show stack traces on deprecations\n" - " --trace-sync-io show stack trace when use of sync IO\n" - " is detected after the first tick\n" - " --track-heap-objects track heap object allocations for heap " - "snapshots\n" - " --prof-process process v8 profiler output generated\n" - " using --prof\n" - " --v8-options print v8 command line options\n" -#if HAVE_OPENSSL - " --tls-cipher-list=val use an alternative default TLS cipher list\n" -#endif -#if defined(NODE_HAVE_I18N_SUPPORT) - " --icu-data-dir=dir set ICU data load path to dir\n" - " (overrides NODE_ICU_DATA)\n" -#if !defined(NODE_HAVE_SMALL_ICU) - " note: linked-in ICU data is\n" - " present.\n" -#endif -#endif - "\n" - "Environment variables:\n" -#ifdef _WIN32 - "NODE_PATH ';'-separated list of directories\n" -#else - "NODE_PATH ':'-separated list of directories\n" -#endif - " prefixed to the module search path.\n" - "NODE_DISABLE_COLORS set to 1 to disable colors in the REPL\n" -#if defined(NODE_HAVE_I18N_SUPPORT) - "NODE_ICU_DATA data path for ICU (Intl object) data\n" -#if !defined(NODE_HAVE_SMALL_ICU) - " (will extend linked-in data)\n" -#endif -#endif - "NODE_REPL_HISTORY path to the persistent REPL history file\n" - "\n" - "Documentation can be found at https://nodejs.org/\n"); + printf(STR_NODEHELP); } @@ -3396,7 +3345,7 @@ static void ParseArgs(int* argc, args_consumed += 1; eval_string = argv[index + 1]; if (eval_string == nullptr) { - fprintf(stderr, "%s: %s requires an argument\n", argv[0], arg); + fprintf(stderr, STR_REQUIRES_ARGUMENT, argv[0], arg); exit(9); } } else if ((index + 1 < nargs) && @@ -3413,7 +3362,7 @@ static void ParseArgs(int* argc, strcmp(arg, "-r") == 0) { const char* module = argv[index + 1]; if (module == nullptr) { - fprintf(stderr, "%s: %s requires an argument\n", argv[0], arg); + fprintf(stderr, STR_REQUIRES_ARGUMENT, argv[0], arg); exit(9); } args_consumed += 1; @@ -3504,7 +3453,7 @@ static void StartDebug(Environment* env, bool wait) { DispatchMessagesDebugAgentCallback); debugger_running = env->debugger_agent()->Start(debug_port, wait); if (debugger_running == false) { - fprintf(stderr, "Starting debugger on port %d failed\n", debug_port); + fprintf(stderr, STR_START_DEBUGGER_FAIL, debug_port); fflush(stderr); return; } @@ -3553,7 +3502,7 @@ static void DispatchDebugMessagesAsyncCallback(uv_async_t* handle) { } while (isolate == nullptr); if (debugger_running == false) { - fprintf(stderr, "Starting debugger agent.\n"); + fprintf(stderr, STR_START_DEBUGGER_AGENT); HandleScope scope(isolate); Environment* env = Environment::GetCurrent(isolate); @@ -3914,7 +3863,7 @@ void Init(int* argc, // Anything that's still in v8_argv is not a V8 or a node option. for (int i = 1; i < v8_argc; i++) { - fprintf(stderr, "%s: bad option: %s\n", argv[0], v8_argv[i]); + fprintf(stderr, "%s: " STR_BAD_OPTION ": %s\n", argv[0], v8_argv[i]); } delete[] v8_argv; v8_argv = nullptr; diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 46e65d055d9161..176ef6ef254101 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -5650,7 +5650,7 @@ void InitCryptoOnce() { #ifdef NODE_FIPS_MODE if (!FIPS_mode_set(1)) { int err = ERR_get_error(); - fprintf(stderr, "openssl fips failed: %s\n", ERR_error_string(err, NULL)); + fprintf(stderr, STR_OPENSSL_FIPS_FAIL, ERR_error_string(err, NULL)); UNREACHABLE(); } #endif // NODE_FIPS_MODE