Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

When a topic function throws, vows are called with the exception passed as topic #280

Open
n2liquid opened this Issue · 3 comments

4 participants

@n2liquid

With this code:

vows.describe('Throwing topic example').addBatch({
    'in this example': {
        topic: function () {
            throw 69;
        },

        'this vow gets called with the thrown value passed as topic... wtf?': function (topic) {
            assert.equal(topic, 69);
        }
    }
}).export(module);

I get this output:

  ♢ Throwing topic example

  in this example
    ✓ this vow gets called with the thrown value passed as topic... wtf?

✓ OK » 1 honored (0.007s)

I would seriously expect a context setup error message and an exception dump, and obviously no vows should be called for that context.

Am I missing something? This doesn't seem to be documented anywhere and I can't see how it could've been by design... Why would it even be desirable?

@n2liquid

Looks like it's by design: https://github.com/cloudhead/vows/blob/c683d8877da94354c4dc428e7f64995afb377441/lib/vows/suite.js#L132-L139

Now the question is... why? Should I assert that the topic is not an exception at the start of every vow then? Should I wrap topic setup in try / catch blocks? And what should I put in the catch clause to abort context execution?

@adamstallard

This is not by design--it is a bug. I fixed it 7 months ago and put in a pull request #263.

The way it's supposed to work is this:

If you have a vow that takes one argument, vows will handle errors for you and output something like:

    in this example
      ✗ this vow gets called with the thrown value passed as topic... wtf?
        » An unexpected error was caught: 69
  ✗ Errored » 1 errored (0.005s)

That's the way it works when I run your code (because I am running my fork).

If you add a second argument to the vow, e.g.,

vows.describe('Throwing topic example').addBatch({
  'in this example': {
    topic: function () {
      throw 69;
    },

    'this vow gets called with the thrown value passed as topic... wtf?': function (error, topic) {
      assert.equal(error, 69);
    }
  }
}).export(module);

then it will behave like you are seeing, because the second argument tells vows that you want to handle your own errors.

Another way to achieve this is by explicitly setting the "error" parameter to false. This is undocumented, but it works like this:

}).export(module, {error: false});

You are welcome to use my fork https://github.com/adamstallard/vows.

I am also considering making a pared-down fork of vows called "vows-core" to use with grunt-vows-runner, that way people can just install grunt-vows-runner using npm and have a fixed version of vows rather than having to use git to install my fork. It depends on how much interest there is.

@dminkovsky

I'm interested in a cleaner version of Vows. Vows is great, but could use a cleanup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.