async-promise-reject-try-catch.ts 483 B

123456789101112
  1. // Rejected promise awaited in a try: `await failure` THROWS the rejection reason
  2. // (the scanner's output), the catch binding receives it, and it reaches the writer.
  3. // Expected: ask#1 -> ask#2 data; ask#2 -> sink.
  4. const finding = await agent("scanner").ask<string>("scan the repo");
  5. const failure: Promise<string> = Promise.reject(finding);
  6. let report = "ok";
  7. try {
  8. await failure;
  9. } catch (e) {
  10. report = String(e);
  11. }
  12. return agent("writer").ask<string>(`summarize: ${report}`);