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

ignoring errors in delegated generators #80

Closed
jonathanong opened this issue Feb 1, 2014 · 0 comments
Closed

ignoring errors in delegated generators #80

jonathanong opened this issue Feb 1, 2014 · 0 comments

Comments

@jonathanong
Copy link
Contributor

i ran into a really weird issue that i finally simplified to a small test case:

function* top() {
  try {
    yield* bottom()
  } catch (err) {
    console.log('caught an error: ' + err.message)
  }
}

function* bottom() {
  try {
    yield undefined
  } catch (err) {
    return // ignore the error
  }
}

var gen = top()
console.log(gen.next())
console.log(gen.throw(new Error('lol')))

i want to ignore specific errors in bottom(). in node 0.11, the result is correct:

{ value: undefined, done: false }
{ value: undefined, done: true }

but in regenerator (specifically gnode) i get:

{ value: undefined, done: false }
caught an error: lol
{ value: undefined, done: true }

seems like regenerator isn't ignoring the error or something. here's the compiled code:

wrapGenerator.mark(bottom);
wrapGenerator.mark(top);

function top() {
  return wrapGenerator(function top$($ctx0) {
    while (1) switch ($ctx0.next) {
    case 0:
      $ctx0.pushTry(5, null, null);
      return $ctx0.delegateYield(bottom(), "t0", 2);
    case 2:
      $ctx0.popCatch(5);
      $ctx0.next = 9;
      break;
    case 5:
      $ctx0.popCatch(5);
      $ctx0.t1 = $ctx0.thrown;
      delete $ctx0.thrown;
      console.log('caught an error: ' + $ctx0.t1.message);
    case 9:
    case "end":
      return $ctx0.stop();
    }
  }, this);
}

function bottom() {
  return wrapGenerator(function bottom$($ctx1) {
    while (1) switch ($ctx1.next) {
    case 0:
      $ctx1.pushTry(6, null, null);
      $ctx1.next = 3;
      return undefined;
    case 3:
      $ctx1.popCatch(6);
      $ctx1.next = 12;
      break;
    case 6:
      $ctx1.popCatch(6);
      $ctx1.t2 = $ctx1.thrown;
      delete $ctx1.thrown;
      delete $ctx1.thrown;
      $ctx1.next = 12;
      break;
    case 12:
    case "end":
      return $ctx1.stop();
    }
  }, this);
}

var gen = top();
console.log(gen.next());
console.log(gen.throw(new Error('lol')));
@benjamn benjamn closed this as completed in b314deb Feb 2, 2014
benjamn added a commit that referenced this issue Feb 2, 2014
Handle .throw method in delegate generator.

Fixes #80.
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

1 participant