Skip to content

Commit

Permalink
fixup! edit error message
Browse files Browse the repository at this point in the history
  • Loading branch information
himself65 committed Jan 12, 2022
1 parent e65bb10 commit 37f2243
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
3 changes: 2 additions & 1 deletion doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,8 @@ The imported module string is an invalid URL, package name, or package subpath
specifier.

<a id="ERR_INVALID_OBJECT_DEFINE_PROPERTY"></a>
### ERR_INVALID_OBJECT_DEFINE_PROPERTY

### ERR\_INVALID\_OBJECT\_DEFINE\_PROPERTY

An error occurred while setting an invalid attribute on the property of
an object.
Expand Down
36 changes: 24 additions & 12 deletions src/node_env_var.cc
Original file line number Diff line number Diff line change
Expand Up @@ -401,20 +401,32 @@ static void EnvDefiner(Local<Name> property,
const PropertyDescriptor& desc,
const PropertyCallbackInfo<Value>& info) {
Environment* env = Environment::GetCurrent(info);
if (desc.has_value() && !desc.configurable() && !desc.enumerable() &&
!desc.writable()) {
THROW_ERR_INVALID_OBJECT_DEFINE_PROPERTY(env,
"Must set all attributes with true to 'value'"
" in 'process.env'");
} else if (desc.has_get() || desc.has_set() ||
(desc.has_configurable() && !desc.configurable()) ||
(desc.has_enumerable() && !desc.enumerable()) ||
(desc.has_writable() && !desc.writable())) {
if (desc.has_value()) {
if (!desc.has_writable() ||
!desc.has_enumerable() ||
!desc.has_configurable()) {
THROW_ERR_INVALID_OBJECT_DEFINE_PROPERTY(env,
"'process.env' only accepts a "
"configurable, writable,"
" and enumerable data descriptor");
} else if (!desc.configurable() || !desc.enumerable() || !desc.writable()) {
THROW_ERR_INVALID_OBJECT_DEFINE_PROPERTY(env,
"'process.env' only accepts a "
"configurable, writable,"
" and enumerable data descriptor");
} else {
return EnvSetter(property, desc.value(), info);
}
} else if (desc.has_get() || desc.has_set()) {
// we don't accept a getter/setter in 'process.env'
THROW_ERR_INVALID_OBJECT_DEFINE_PROPERTY(env,
"Cannot set attributes other than 'value'"
" for properties in 'process.env'");
"'process.env' does not accept an"
"accessor(getter/setter) descriptor");
} else {
EnvSetter(property, desc.value(), info);
THROW_ERR_INVALID_OBJECT_DEFINE_PROPERTY(env,
"'process.env' only accepts a "
"configurable, writable,"
" and enumerable data descriptor");
}
}

Expand Down
14 changes: 8 additions & 6 deletions test/parallel/test-process-env-ignore-getter-setter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ assert.throws(
{
code: 'ERR_INVALID_OBJECT_DEFINE_PROPERTY',
name: 'TypeError',
message: 'Must set all attributes with true to \'value\' ' +
'in \'process.env\''
message: '\'process.env\' only accepts a ' +
'configurable, writable,' +
' and enumerable data descriptor'
}
);

Expand All @@ -32,8 +33,8 @@ assert.throws(
{
code: 'ERR_INVALID_OBJECT_DEFINE_PROPERTY',
name: 'TypeError',
message: 'Cannot set attributes other than \'value\' ' +
'for properties in \'process.env\''
message: '\'process.env\' does not accept an' +
'accessor(getter/setter) descriptor'
}
);

Expand All @@ -49,8 +50,9 @@ attributes.forEach((attribute) => {
{
code: 'ERR_INVALID_OBJECT_DEFINE_PROPERTY',
name: 'TypeError',
message: 'Cannot set attributes other than \'value\' ' +
'for properties in \'process.env\''
message: '\'process.env\' only accepts a ' +
'configurable, writable,' +
' and enumerable data descriptor'
}
);
});
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-worker-process-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ if (!workerData && process.argv[2] !== 'child') {
{
code: 'ERR_INVALID_OBJECT_DEFINE_PROPERTY',
name: 'TypeError',
message: 'Must set all attributes with true to \'value\' ' +
'in \'process.env\''
message: '\'process.env\' only accepts a configurable, ' +
'writable, and enumerable data descriptor'
}
);

Expand Down

0 comments on commit 37f2243

Please sign in to comment.