-
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
ERR_MODULE_NOT_FOUND: add a property to exception object to hold failing import's argument #37581
Comments
Thanks for raising this — the request sounds reasonable. Hope to take a deeper look a bit later. Curious what others may think on the matter. /cc @nodejs/modules |
A custom loader doesn't sound like overkill at all to me - it's precisely what you're trying to achieve. The other adjectives, however, are likely true at this time. |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
@DerekNonGeneric is it "a bit later" yet? ;) |
Doesn’t the error message included with |
... when node is running with English locale. |
Does Node have non-English error messages when it’s running in other locales? |
It either has, or might have at some point in the future, which is still a sufficient reason not to rely on parsing natural language. |
Even if it wouldn’t ever be anything but English, i would think it’d be a horrifying suggestion to tell people to parse natural language. The message is for humans, only - the stuff for programs is “other properties”. |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
No bot, no. I'm still rooting for this. |
Node.js recently added support for |
It wouldn't. I need the exact byte-for-byte string that was passed as the argument to EDIT: it might work if the entire chain down to the failed dependency is recorded using the |
This comment was marked as abuse.
This comment was marked as abuse.
Is the resolution here to add a custom loader with My intuition is that adding more properties to the ERR_MODULE_NOT_FOUND exception object complicates writing third-party loaders but maybe I'm mistaken here. |
I think that's one way to achieve the request today, yes, but it's a bit much to write a custom loader to improve a Node error message. I think a reasonable solution would be to add the specifier of the failing import to the |
The rationale for my original request is not to improve error messages, though that would be an extra benefit. I need the feature to be able to implement special-purpose loading logic correctly in the first place, without resorting to the check-existence-and-load antipattern. As it is, the error doesn't supply necessary information to make the key decision in the algorithm: whether to try another candidate specifier (because this one didn't resolve to an existing file) or to rethrow (because the file was found, but contained errors). I insist that the first question one asks when being presented with an error object is, "What failed?", and answering this question is the error object's primary job. In this case the specifier is the what. Unless someone is doing something really exotic with ERR_MODULE_NOT_FOUND objects, like validating their structure against an inextensible schema, I can't imagine a scenario where adding a super-relevant property under already standardized |
@rulatir This request has been open for two years without anyone expressing interest in implementing this enhancement. If you want to see it happen you might need to make a PR yourself. A good place to start is https://github.com/nodejs/node/blob/main/CONTRIBUTING.md. |
... and custom loaders are still under a flag.
If I must in fact sit down and write the code myself, what provisions in the LICENSE compel or incentivize me to |
Okay, close it is. I don't see this discussion taking a productive turn. @rulatir don't let the door hit you on the way out. |
Is your feature request related to a problem? Please describe.
I am developing a framework that uses node as a host for user scripts. The framework loads them dynamically with the async
import()
function, and the userscripts can also import other modules withimport
statement.When I call that
import()
function, I basically want to rethrow all errors thrown by it, except for one very specific condition: when theimport()
function fails withERR_MODULE_NOT_FOUND
because the userscript file itself wasn't present in the location just tried. The userscript might still be found in some other search path, which is why its absence in any given candidate location is not an error. If however theimport()
function failed withERR_MODULE_NOT_FOUND
because some other module imported by the userscript was not found, then I want to rethrow that error.Describe the solution you'd like
Add a property to the exception object thrown for
ERR_MODULE_NOT_FOUND
that will hold the exact value of the argument that was given to the failingimport
function or statement.Describe alternatives you've considered
I considered checking for existence first and then attempting to
import()
, but that is a known antipattern.I considered parsing the
message
orstack
property, but that would be a hack. These properties are probably locale dependent and their format is not set in stone.I looked into custom loaders and found the subject difficult, scary, apparently indefinitely experimental, and an overkill for this particular purpose. I need a simple and reliable way.
The text was updated successfully, but these errors were encountered: