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

Dust does not propagate thrown errors from a helper if async onLoad is used #481

Closed
cpettitt opened this issue Jun 18, 2014 · 6 comments
Closed

Comments

@cpettitt
Copy link

Recently error propagation was fixed for most asynchronous cases (see #471). However, this still leaves open the possibility of losing failures in onLoad. The following is a copy of details from #471 (comment).

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)

For now we have disabled onLoad for our use cases, but we'd like to re-enable it once it is safe.

@sethkinast
Copy link
Contributor

I believe I fixed this in #495, could you confirm?

I tried to repro and see:

STREAM DATA  test.htm:26
STREAM ERROR Error {stack: (...), message: "Ooops!"}

@cpettitt
Copy link
Author

Great! That output indicates that the problem I was seeing is fixed.

@sethkinast
Copy link
Contributor

Great, thanks for taking the time to take a peek.

@edobry
Copy link

edobry commented Apr 2, 2015

Is there anything I need to enable to make this work? I'm using v2.6.2 and errors are still being swallowed.

@sethkinast
Copy link
Contributor

Could you provide an example of your code that results in no error?

@edobry
Copy link

edobry commented Oct 27, 2015

Not at the moment, it's all tangled up with other code. I tried both dust.debugLevel = "DEBUG" and dust.isDebug = true and neither seemed to help. Is there something obvious I'm missing maybe?

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

No branches or pull requests

3 participants