Skip to content

Commit 1dd28bf

Browse files
committed
doc: correct util.convertProcessSignalToExitCode validation behavior
1 parent d9f2226 commit 1dd28bf

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

doc/api/util.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,35 +89,36 @@ callbackFunction((err, ret) => {
8989
});
9090
```
9191

92-
## `util.convertProcessSignalToExitCode(signalCode)`
92+
## `util.convertProcessSignalToExitCode(signal)`
9393

9494
<!-- YAML
9595
added:
9696
- v25.4.0
9797
- v24.14.0
9898
-->
9999

100-
* `signalCode` {string} A signal name (e.g., `'SIGTERM'`, `'SIGKILL'`).
101-
* Returns: {number|null} The exit code, or `null` if the signal is invalid.
100+
* `signal` {string} A signal name (e.g. `'SIGTERM'`)
101+
* Returns: {number} The exit code corresponding to `signal`
102102

103103
The `util.convertProcessSignalToExitCode()` method converts a signal name to its
104104
corresponding POSIX exit code. Following the POSIX standard, the exit code
105105
for a process terminated by a signal is calculated as `128 + signal number`.
106106

107+
If `signal` is not a valid signal name, then an error will be thrown. See
108+
[`signal(7)`][] for a list of valid signals.
109+
107110
```mjs
108111
import { convertProcessSignalToExitCode } from 'node:util';
109112

110113
console.log(convertProcessSignalToExitCode('SIGTERM')); // 143 (128 + 15)
111114
console.log(convertProcessSignalToExitCode('SIGKILL')); // 137 (128 + 9)
112-
console.log(convertProcessSignalToExitCode('INVALID')); // null
113115
```
114116

115117
```cjs
116118
const { convertProcessSignalToExitCode } = require('node:util');
117119

118120
console.log(convertProcessSignalToExitCode('SIGTERM')); // 143 (128 + 15)
119121
console.log(convertProcessSignalToExitCode('SIGKILL')); // 137 (128 + 9)
120-
console.log(convertProcessSignalToExitCode('INVALID')); // null
121122
```
122123

123124
This is particularly useful when working with processes to determine
@@ -3869,6 +3870,7 @@ npx codemod@latest @nodejs/util-is
38693870
[`mime.toString()`]: #mimetostring
38703871
[`mimeParams.entries()`]: #mimeparamsentries
38713872
[`napi_create_external()`]: n-api.md#napi_create_external
3873+
[`signal(7)`]: https://man7.org/linux/man-pages/man7/signal.7.html
38723874
[`target` and `handler`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#terminology
38733875
[`tty.hasColors()`]: tty.md#writestreamhascolorscount-env
38743876
[`util.diff()`]: #utildiffactual-expected

0 commit comments

Comments
 (0)