-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: add test for error codes doc and impl #21470
Conversation
/cc @nodejs/tsc this is a bit hacky test, so I would be happy with some extra feedback on that. |
I like the idea, a few notes:
This does not apply to errors that are removed (those are the |
// File containing error definitions | ||
const jsdata = natives['internal/errors']; | ||
// File containing error documentation | ||
const docdata = fs.readFileSync('doc/api/errors.md', 'utf-8'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this an absolute path so that it can be run somewhere other than the project directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks @joyeecheung!
Great idea :-) |
But unused errors were removed multiple times from documentation. E.g.:
Were all those done in strictly before those errors got into some releases? I expect not. |
927305c
to
0bc333a
Compare
I added a doc sorting/formatting check (see above, I updated the post), this is what it currently prints: doc: ERR_HTTP2_HEADERS_AFTER_RESPOND - is out of order
doc: ERR_STREAM_DESTROYED - is out of order
doc: ERR_TLS_RENEGOTIATION_DISABLED - is out of order I think it makes sense to sort the error codes in docs, as the current order looks like:
Which is not ideal. Also, this prevents future duplicate errors like what e9358af fixed — we had duplicate entries at some point. |
98c37fe
to
3f639f2
Compare
One more check added: all doc entries should have appropriate anchors. doc: ERR_SCRIPT_EXECUTION_TIMEOUT - missing anchor or not properly formatted |
3f639f2
to
d2094e8
Compare
d2094e8
to
ee09862
Compare
Updated with a scan of all impl: ERR_HTTP2_STREAM_CLOSED - missing implementation, mentioned in doc/api/ |
bbc374f
to
69d2df3
Compare
This restores a broken and erroneously removed error, which was accidentially renamed to ERR_MISSING_DYNAMIC_INTSTANTIATE_HOOK (notice the "INTST" vs "INST") in 921fb84 (PR nodejs#16874) and then had documentation and implementation removed under the old name in 6e1c25c (PR nodejs#18857), as it appeared unused. This error code never worked or was documented under the mistyped name ERR_MISSING_DYNAMIC_INTSTANTIATE_HOOK, so renaming it back to ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK is a semver-patch fix. Refs: nodejs#21440 Refs: nodejs#21470 Refs: nodejs#16874 Refs: nodejs#18857
This restores a broken and erroneously removed error, which was accidentially renamed to ERR_MISSING_DYNAMIC_INTSTANTIATE_HOOK (notice the "INTST" vs "INST") in 921fb84 (PR #16874) and then had documentation and implementation removed under the old name in 6e1c25c (PR #18857), as it appeared unused. This error code never worked or was documented under the mistyped name ERR_MISSING_DYNAMIC_INTSTANTIATE_HOOK, so renaming it back to ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK is a semver-patch fix. Refs: #21440 Refs: #21470 Refs: #16874 Refs: #18857 PR-URL: #21493 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ron Korving <ron@ronkorving.nl> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This restores a broken and erroneously removed error, which was accidentially renamed to ERR_MISSING_DYNAMIC_INTSTANTIATE_HOOK (notice the "INTST" vs "INST") in 921fb84 (PR #16874) and then had documentation and implementation removed under the old name in 6e1c25c (PR #18857), as it appeared unused. This error code never worked or was documented under the mistyped name ERR_MISSING_DYNAMIC_INTSTANTIATE_HOOK, so renaming it back to ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK is a semver-patch fix. Refs: #21440 Refs: #21470 Refs: #16874 Refs: #18857 PR-URL: #21493 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ron Korving <ron@ronkorving.nl> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
The old error code `ERR_HTTP2_STREAM_CLOSED` was removed in commit 0babd18 (pull request nodejs#17406), and the testcase for http2stream.pushStream was changed accordingly, but the documentation change was overlooked. This commit fixes it and aligns the documentation with the testcase. This is a part of the fixes hinted by nodejs#21470, which includes some tests for error codes usage and documentation and enforces a stricter format. Refs: nodejs#21470 Refs: nodejs#17406 PR-URL: nodejs#21487 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
The old error code `ERR_HTTP2_STREAM_CLOSED` was removed in commit 0babd18 (pull request #17406), and the testcase for http2stream.pushStream was changed accordingly, but the documentation change was overlooked. This commit fixes it and aligns the documentation with the testcase. This is a part of the fixes hinted by #21470, which includes some tests for error codes usage and documentation and enforces a stricter format. Refs: #21470 Refs: #17406 PR-URL: #21487 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
d731824
to
cf25ca2
Compare
cf25ca2
to
ac8b182
Compare
All the known issues with error codes were resolved (in other PRs), this should pass now. |
@nodejs/testing |
The old error code `ERR_HTTP2_STREAM_CLOSED` was removed in commit 0babd18 (pull request nodejs#17406), and the testcase for http2stream.pushStream was changed accordingly, but the documentation change was overlooked. This commit fixes it and aligns the documentation with the testcase. This is a part of the fixes hinted by nodejs#21470, which includes some tests for error codes usage and documentation and enforces a stricter format. Refs: nodejs#21470 Refs: nodejs#17406 PR-URL: nodejs#21487 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This adds several sanity checks for error codes. It scans: * all natives (js sources), * doc/api/*.md documentation * src/node_errors.h (errors definition from the C++ side). There is also a whitelist of manually created errors from JS side, currently consisting of ERR_HTTP2_ERROR and ERR_UNKNOWN_BUILTIN_MODULE. Alsom all ERR_NAPI_ codes are whitelisted, as those are created directly on the cpp side, without declaring them first. The performed checks: 1. All errors used from JS should be defined in `internal/errors` and present in its .codes object. Whitelist (mentioned above) applies. 2. All errors instantiated from JS without arguments should support 0-arguments version. 3. All errors mentioned in doc should defined either in JS, C++, or in the whitelist. 4. All errors mentioned anywhere should be documented. 5. Documentation of error codes should be sorted, have no repeats, and include exactly one entry for every error code mentioned in the documentation, formatted as `/\n### (ERR_[A-Z0-9_]+)\n`. 6. All doc entries for error codes should have appropriate anchors. There is also a --report flag, which prints all the current issues and exits without asserting, for manual inspection. Individual fixes for those issues are landed in separate commits. Refs: nodejs#21421 Refs: nodejs#21440 Refs: nodejs#21483 Refs: nodejs#21484 Refs: nodejs#21485 Refs: nodejs#21487 PR-URL: nodejs#21470
ac8b182
to
8e41fd7
Compare
Ping everyone again ;-). |
|
||
// Check that we can initialize errors called without args | ||
for (const name of set.noargs) { | ||
if (!errors[name]) continue; // Already catched that above |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catched -> caught
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great test! Just left a few suggestions as I believe this could still be improved and we currently have a few custom eslint rules that test for the order and existence without being fully reliable. Since those rules do not work properly all the time (e.g., they do not detect changed docs right away) it would probably be best to remove those in favor of this test.
for (const file of fs.readdirSync(docdir)) { | ||
if (!file.endsWith('.md')) continue; | ||
let data = fs.readFileSync(path.join(docdir, file), 'utf-8'); | ||
if (file === 'errors.md') data = data.replace(/## Legacy [\s\S]*/, ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should docdata
maybe just be read here? That way the file must only be read once instead of twice.
|
||
function addSource(source, type) { | ||
// eslint-disable-next-line node-core/no-unescaped-regexp-dot | ||
const re = /(.)?(ERR_[A-Z0-9_]+)(..)?/g; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand the regexp correct the last part is there to potentially match a JS error called without arguments. If that's the case, could we just change this to: (\(\))?
?
const report = process.argv[2] === '--report'; | ||
const results = []; | ||
function check(ok, type, name, reason) { | ||
const label = `${type}: ${name} - ${reason}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the last three argument combined become the label, wouldn't it be best to pass through the label directly?
const natives = process.binding('natives'); | ||
|
||
// --report prints only the list of failed checks and does not assert | ||
const report = process.argv[2] === '--report'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to change that to always asserting but checking all entries first instead of asserting on the first failure.
That way the failures are obvious from the assertion and the user does not have to run the test with this flag (and it's not that obvious that this flag must be used by just taking a glimpse at this).
The old error code `ERR_HTTP2_STREAM_CLOSED` was removed in commit 0babd18 (pull request nodejs#17406), and the testcase for http2stream.pushStream was changed accordingly, but the documentation change was overlooked. This commit fixes it and aligns the documentation with the testcase. This is a part of the fixes hinted by nodejs#21470, which includes some tests for error codes usage and documentation and enforces a stricter format. Refs: nodejs#21470 Refs: nodejs#17406 PR-URL: nodejs#21487 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
The old error code `ERR_HTTP2_STREAM_CLOSED` was removed in commit 0babd18 (pull request nodejs#17406), and the testcase for http2stream.pushStream was changed accordingly, but the documentation change was overlooked. This commit fixes it and aligns the documentation with the testcase. This is a part of the fixes hinted by nodejs#21470, which includes some tests for error codes usage and documentation and enforces a stricter format. Refs: nodejs#21470 Refs: nodejs#17406 PR-URL: nodejs#21487 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
The old error code `ERR_HTTP2_STREAM_CLOSED` was removed in commit 0babd18 (pull request #17406), and the testcase for http2stream.pushStream was changed accordingly, but the documentation change was overlooked. This commit fixes it and aligns the documentation with the testcase. This is a part of the fixes hinted by #21470, which includes some tests for error codes usage and documentation and enforces a stricter format. Refs: #21470 Refs: #17406 Backport-PR-URL: #22850 PR-URL: #21487 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
@ChALkeR Still hoping to land this? |
Ping @ChALkeR |
Closing this due to inactivity. Please reopen if needed. |
This adds several sanity checks for error codes, ref: #21440.
An early version of this test was used to find #21440 (and is something I came up after seeing #21421).
It scans:
doc/api/*.md
documentationsrc/node_errors.h
(errors definition from the C++ side).There is also a whitelist of manually created errors from JS side, currently consisting of
ERR_HTTP2_ERROR
andERR_UNKNOWN_BUILTIN_MODULE
. That could be improved, I guess.The performed checks:
internal/errors
and present in its.codes
object.Whitelist with two exceptions of manually created errors (listed above) applies.
As in
new ERR_SOMETHING()
, ref: fs: fsPromises.lchmod throws AssertionError on Ubuntu #21421.internal/errors
), C++ (src/node_errors.h
), or in the whitelist with two manually created errors./\n### (ERR_[A-Z0-9_]+)\n
for every error code mentioned in the documentation.The checks are a bit hacky (and scan the source code as text), but they work and I would prefer keeping it simple as we have a common markup for all those.
There is also a
--report
flag, which prints all the current issues and exits without asserting, for manual inspection.Current output on v10.5.0:
I believe that all those are actual problems that need to be fixed.
This test currently fails and is blocked on #21440, i.e. fixing all those errors.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes