Skip to content
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

Merged
merged 4 commits into from
Jun 11, 2014

Conversation

prashn64
Copy link
Contributor

@prashn64 prashn64 commented Jun 5, 2014

when rendering or streaming

…acks are always invoked when rendering or streaming
@jimmyhchan
Copy link
Contributor

Travis failed?

@cpettitt
Copy link

cpettitt commented Jun 5, 2014

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.

@cpettitt
Copy link

cpettitt commented Jun 5, 2014

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

@cpettitt
Copy link

cpettitt commented Jun 5, 2014

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:

STREAM DATA  index.html:26
Uncaught Error: Ooops! index.html:15
dust.helpers.bad index.html:15
Chunk.helper dust-full.js:787
body_0 VM335:1
(anonymous function) dust-full.js:156
(anonymous function)

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.

@jimmyhchan
Copy link
Contributor

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",
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed.

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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

Prayrit Jain added 3 commits June 6, 2014 13:09
…he same function, remove error throwing from dust.log, and set a chunk error when dust helper errors are caught
@jimmyhchan
Copy link
Contributor

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, chunk.fail.

@kate2753
Copy link
Contributor

Looks good to me.

What is the use case for throwing real errors? Keep in mind that both dust.render and dust.stream are asynchronous and wrapping those calls in try\catch won't catch real errors thrown.

@smfoote
Copy link
Contributor

smfoote commented Jun 10, 2014

Looks good to me, too.

On Tue, Jun 10, 2014 at 2:39 PM, Kate Odnous notifications@github.com
wrote:

Looks good to me.

What is the use case for throwing real errors? Keep in mind that both
dust.render and dust.stream are asynchronous and wrapping those calls in
try\catch won't catch real errors thrown.


Reply to this email directly or view it on GitHub
#471 (comment).

jimmyhchan added a commit that referenced this pull request Jun 11, 2014
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
@jimmyhchan jimmyhchan merged commit 12d8690 into linkedin:master Jun 11, 2014
@cpettitt
Copy link

Did we do anything to address the asynchronous load problem mentioned in #471 (comment)? If not, should I open a separate ticket for that?

@prashn64
Copy link
Contributor Author

Yeah, let's open up a new ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants