Skip to content

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

@Raynos

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 )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions