Skip to content

return new Error() vs yield new Error() #7

Description

@Raynos

Currently in this spec you can write a generator function that fails with

function* gen(args) {
  if (notRight(args)) {
    return new Error("args error")
  }
}

This allows you to return run time errors without throwing them.

However this breaks with yield*

function* gen2() {
  var value = yield* gen()
  // value == error wtf ?
}

The expected behaviour is that the error from gen() bubbles up through the yield* in gen2

The only way to fix that would be to have yield new Error("args error") instead.

I landed a commit with the fix in gens ( Raynos/gens@49b8c6e )

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions