-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Missing process functions under workers should throw explicit error #25448
Comments
I think the fact that it breaks feature detection means this proposal is DOA. Maybe other collaborators feel differently? |
It sounds reasonable to me to have a version of |
That'd certainly be nice! That would help in Would it be possible to get a list of missing APIs from const { removedProcessFunctions, isMainThread } = require('worker_threads');
if (!isMainThread) {
removedProcessFunctions.forEach(func => {
Object.defineProperty(process, func, {
value: () => {
throw new Error(func + ' is not available inside a worker');
}
});
});
} Not sure how that plays with feature detection either (or how prevalent feature detection on |
It would break detection. However, since worker threads are still experimental, I think it makes sense to add worker-specific stubs that throw. |
Refs: nodejs#25448 PR-URL: nodejs#25526 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
Refs: #25448 PR-URL: #25526 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
Thank you! 🎉 |
Some process methods are not supported in workers. This commit adds stubs that throw more informative errors. PR-URL: #25587 Fixes: #25448 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]>
Is your feature request related to a problem? Please describe.
Jest calls
mkdirp
during its unit tests. Jest has also recently added support forworker_threads
. However, when I wanted to try it out, hundreds of tests failed withTypeError: process.umask is not a function
It turn out
mkdirp
usesprocess.umask()
if nomode
is provided: https://github.com/substack/node-mkdirp/blob/f2003bbcffa80f8c9744579fabab1212fc84545a/index.js#L64I've since found that this function missing in
worker_threads
is well documented: https://nodejs.org/api/worker_threads.html#worker_threads_class_workerDescribe the solution you'd like
If node could throw "
process.umask
is not available in worker threads" or similar it would have made my debugging way easier, rather than the function just be missing.I'm not sure how that would play with
typeof process.umask === 'function'
checks people might have?Describe alternatives you've considered
My solution was to pass
777
as mode explicitly tomkdirp
, but a clearer error would have made the debugging way easier.My use case might be a bit special since Jest reconstructs a fake
process
object for every single test (by inspecting the real one), so my rabbit hole before checking worker docs were probably deeper than most people in the same situation. I was also testing node 12 (where threads are unflagged), so I wasn't even aware I was running in threads at first.The text was updated successfully, but these errors were encountered: