Skip to content

Commit b61d31a

Browse files
dtokijasnell
authored andcommitted
src: add deprecation warning to errname()
PR-URL: #23597 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
1 parent 188ffcb commit b61d31a

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed

doc/api/deprecations.md

+16
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,21 @@ like `dns.lookup(false)` due to backward compatibility.
22332233
This behavior is undocumented and is thought to be unused in real world apps.
22342234
It will become an error in future versions of Node.js.
22352235
2236+
<a id="DEP0119"></a>
2237+
### DEP0119: process.binding('uv').errname() private API
2238+
<!--
2239+
changes:
2240+
- version: REPLACEME
2241+
pr-url: https://github.com/nodejs/node/pull/23597
2242+
description: Documentation-only deprecation.
2243+
-->
2244+
2245+
Type: Documentation-only (supports [`--pending-deprecation`][])
2246+
2247+
Directly calling `process.binding('uv').errname(<val>)` is deprecated.
2248+
Please make sure to use [`util.getSystemErrorName()`][] instead.
2249+
2250+
22362251
[`--pending-deprecation`]: cli.html#cli_pending_deprecation
22372252
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
22382253
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
@@ -2300,6 +2315,7 @@ It will become an error in future versions of Node.js.
23002315
[`util._extend()`]: util.html#util_util_extend_target_source
23012316
[`util.debug()`]: util.html#util_util_debug_string
23022317
[`util.error()`]: util.html#util_util_error_strings
2318+
[`util.getSystemErrorName()`]: util.html#util_util_getsystemerrorname_err
23032319
[`util.inspect()`]: util.html#util_util_inspect_object_options
23042320
[`util.inspect.custom`]: util.html#util_util_inspect_custom
23052321
[`util.isArray()`]: util.html#util_util_isarray_object

src/env.cc

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ Environment::Environment(IsolateData* isolate_data,
134134
printed_error_(false),
135135
abort_on_uncaught_exception_(false),
136136
emit_env_nonstring_warning_(true),
137+
emit_err_name_warning_(true),
137138
makecallback_cntr_(0),
138139
should_abort_on_uncaught_toggle_(isolate_, 1),
139140
trace_category_state_(isolate_, kTraceCategoryCount),

src/env.h

+7
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,12 @@ class Environment {
843843
return current_value;
844844
}
845845

846+
inline bool EmitErrNameWarning() {
847+
bool current_value = emit_err_name_warning_;
848+
emit_err_name_warning_ = false;
849+
return current_value;
850+
}
851+
846852
typedef void (*native_immediate_callback)(Environment* env, void* data);
847853
// cb will be called as cb(env, data) on the next event loop iteration.
848854
// obj will be kept alive between now and after the callback has run.
@@ -929,6 +935,7 @@ class Environment {
929935
bool printed_error_;
930936
bool abort_on_uncaught_exception_;
931937
bool emit_env_nonstring_warning_;
938+
bool emit_err_name_warning_;
932939
size_t makecallback_cntr_;
933940
std::vector<double> destroy_async_id_list_;
934941

src/uv.cc

+9-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,17 @@ using v8::String;
3939
using v8::Value;
4040

4141

42-
// TODO(joyeecheung): deprecate this function in favor of
43-
// lib/util.getSystemErrorName()
4442
void ErrName(const FunctionCallbackInfo<Value>& args) {
4543
Environment* env = Environment::GetCurrent(args);
44+
if (env->options()->pending_deprecation && env->EmitErrNameWarning()) {
45+
if (ProcessEmitDeprecationWarning(
46+
env,
47+
"Directly calling process.binding('uv').errname(<val>) is being"
48+
" deprecated. "
49+
"Please make sure to use util.getSystemErrorName() instead.",
50+
"DEP0119").IsNothing())
51+
return;
52+
}
4653
int err;
4754
if (!args[0]->Int32Value(env->context()).To(&err)) return;
4855
CHECK_LT(err, 0);
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
// Flags: --pending-deprecation
5+
6+
common.expectWarning(
7+
'DeprecationWarning',
8+
'Directly calling process.binding(\'uv\').errname(<val>) is being ' +
9+
'deprecated. Please make sure to use util.getSystemErrorName() instead.',
10+
'DEP0119'
11+
);
12+
13+
process.binding('uv').errname(-1);

0 commit comments

Comments
 (0)