-
Notifications
You must be signed in to change notification settings - Fork 479
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
set errors on the chunk when catching errors so that the proper callbacks are invoked... #471
Conversation
…acks are always invoked when rendering or streaming
Travis failed? |
I see this on my unrelated node repos too. It seems that some common node dependency (minimatch) is no longer available in node 0.8. |
More details on the minimatch problem: isaacs/minimatch#35. The following .travis.yml snippet from the linked issue fixed it for one of my projects: before_install: npm update -g npm |
I confirmed this fixes the immediate failures I'm seeing. However, this still leaves open the possibility of losing failures in onLoad. Here's an example: <!doctype html>
<script src="dust-full.js"></script>
<script>
dust.onLoad = function(name, callback) {
dust.nextTick(function() {
switch (name) {
case 'bad': callback(null, "BEFORE_BAD {@bad/} AFTER_BAD"); break;
default: callback('No such template!'); break;
}
});
};
dust.helpers.bad = function() {
throw new Error("Ooops!");
};
var stream;
try {
stream = dust.stream("bad", {});
} catch (e) {
console.log("DUST STREAM THREW", e);
}
stream.on("data", function(data) {
console.log("STREAM DATA", data);
});
stream.on("error", function(err) {
console.log("STREAM ERROR", err);
});
stream.on("end", function() {
console.log("STREAM END");
});
</script> The chrome console shows an empty chunk followed by an uncaught error:
Still, this change is a big improvement over the current state. I'd be happy to have it. We may just have to disable lazy template loading until the larger issue is resolved. |
Looks like our dev dependency grunt-template-jasmine-istanbul uses fileset which specifies only 0.X for minimatch https://github.com/mklabs/node-fileset. 0.8 will be all but lost if Grunt moves to minimatch 0.3 |
@@ -1829,19 +1829,6 @@ var coreTests = [ | |||
message: "test the log messages for an existing not exists check." | |||
}, | |||
{ | |||
name: "Errors should be propogated if the silenceErrors flag is not set", |
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 not backwards compatible. 2.4?
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.
agreed.
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.
Errors are still propagated, but in the way that you can actually catch them :). I don't mind bumping to 2.4 though.
With this change do we still need dust.silenceErrors flag?
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.
+1 deprecate silenceErrors and deprecate dust.log throwing errors.
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.
Check the new dust.throwError. It's still useful if you want to continue rendering in certain cases when throwing an error.
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.
throwError is a misnomer.... maybe dust.fail
instead? If so, it should fail pretty catastrophically.
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.
or... chunk.fail
so that it's scoped to within the helper user function code.
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.
as discussed there isn't really a use case for trying to throw errors since they are meaningless for the async cases.
for consistency, if you want to throw use chunk.setError
and if you want to catch look in the errorback
…he same function, remove error throwing from dust.log, and set a chunk error when dust helper errors are caught
This looks good for a 2.4 release (since we deprecated so much stuff). We should do something for those who want to throw real errors (see #381) for example, |
Looks good to me. What is the use case for throwing real errors? Keep in mind that both |
Looks good to me, too. On Tue, Jun 10, 2014 at 2:39 PM, Kate Odnous [email protected]
|
Errors thrown from render will now call populate the error in the callback. Previously, thrown errors will immediately fail and not call the callback. Issue #381, Address #468: Errors thrown from stream now will invoke the `error` listener with the error object. Previously, these errors could not be caught and the process will hang. Deprecated/remove: `dust.onError`, `dust.silenceErrors`. To see runtime errors, look at the error in the callback. breaking change: `dust.log` with an error no longer throws that error
Did we do anything to address the asynchronous load problem mentioned in #471 (comment)? If not, should I open a separate ticket for that? |
Yeah, let's open up a new ticket. |
when rendering or streaming