Bug report: errors requiring module not thrown when loaded from cache

Showing 1-4 of 4 messages
Bug report: errors requiring module not thrown when loaded from cache Devon Govett 2/20/11 9:16 PM
Versions tested: v0.4, v0.4.1

If you require a module that has an error (such as a parse error) in
it within a try block so that it doesn't kill your program, the errors
will be thrown and passed to your catch block as expected.  However,
if you then tried to load that same module in again later, the error
does not get thrown and an empty object is returned.  Here is an
example:

Say that the module 'foo' has a parse error in it.

try {
    foo = require('./foo');
} catch(e) {
    console.log(e.message); // Parse error...
}

try {
    bar = require('./foo');
} catch(e) {
    console.log(e.message); // Never reached
}

console.log(bar); // {}

Looking in require.cache after foo is loaded the first time shows that
the module was cached even though there were errors.  This seems like
a bug to me.  What do you think?
Re: Bug report: errors requiring module not thrown when loaded from cache Felix Geisendörfer 2/21/11 6:53 AM
I think it is a bug as well. Here is a test case + fix:


Ryan: I also tried to send you a pull request for this, but GitHub seems to have fucked it up, so ignore it:

https://github.com/ry/node/pull/710 (seems like it got mixed up with other comments and commits).

--fg
Re: [node-dev] Bug report: errors requiring module not thrown when loaded from cache Isaac Z. Schlueter 2/21/11 6:39 AM
Yes, that is definitely a bug.  Modules shouldn't be cached if they throw.
Re: Bug report: errors requiring module not thrown when loaded from cache ry 2/24/11 4:16 PM
Thanks felix. landed in 66601f13d9f841fe4e644a0b106ea3106054f46a