Skip to content

Commit 746b9b2

Browse files
committed
adds deprication warning to errname()
1 parent 714c1b8 commit 746b9b2

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

doc/api/deprecations.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,6 +2230,13 @@ like `dns.lookup(false)` due to backward compatibility.
22302230
This behavior is undocumented and is thought to be unused in real world apps.
22312231
It will become an error in future versions of Node.js.
22322232
2233+
<a id="DEP0XXX"></a>
2234+
### DEP0XXX: process.binding('uv').errname() private API
2235+
2236+
Type: Documentation-only (supports [`--pending-deprecation`][])
2237+
2238+
2239+
22332240
[`--pending-deprecation`]: cli.html#cli_pending_deprecation
22342241
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
22352242
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array

src/env.cc

Lines changed: 1 addition & 0 deletions
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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,11 @@ class Environment {
842842
emit_env_nonstring_warning_ = false;
843843
return current_value;
844844
}
845+
inline bool EmitErrNameWarning() {
846+
bool current_value = emit_err_name_warning_;
847+
emit_err_name_warning_ = false;
848+
return current_value;
849+
}
845850

846851
typedef void (*native_immediate_callback)(Environment* env, void* data);
847852
// cb will be called as cb(env, data) on the next event loop iteration.
@@ -929,6 +934,7 @@ class Environment {
929934
bool printed_error_;
930935
bool abort_on_uncaught_exception_;
931936
bool emit_env_nonstring_warning_;
937+
bool emit_err_name_warning_;
932938
size_t makecallback_cntr_;
933939
std::vector<double> destroy_async_id_list_;
934940

src/uv.cc

Lines changed: 9 additions & 2 deletions
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+
"DEP0XXX").IsNothing())
51+
return;
52+
}
4653
int err;
4754
if (!args[0]->Int32Value(env->context()).To(&err)) return;
4855
CHECK_LT(err, 0);
Lines changed: 13 additions & 0 deletions
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+
'DEP0XXX'
11+
);
12+
13+
process.binding('uv').errname(-1);

0 commit comments

Comments
 (0)