docs: add async error handling example#2504
Conversation
Add an example demonstrating best practices for handling errors in async action handlers, including retry logic and batch processing.
Have you got any references to new developers having problems? Most of the problems people have reported in issues are:
However, having an async error example is still a reasonable suggestion! I have different ideas about what to focus on to discuss. |
|
Hi @shadowspawn, thanks so much for the thoughtful feedback! 🙏 To be completely honest, I don't have hard references or issue links to back up my claim about "new developers having problems" — that was more based on my own personal experience when I first started using Commander with async actions. I remember being a bit confused about whether to use Looking at the related issues you linked (#1144, #1777, #1898, #2325), I can see the actual pain points are a bit different from what I focused on here — especially the I'd love to revise this example to focus on the things that actually trip people up. Would you be open to me updating the PR to:
I'm totally happy to pivot this in whatever direction you think would be most helpful for the examples directory. Let me know what you'd prefer to see! 😊 |
|
Yes please, a pivot. I do think the retry/batch is a bit noisy. Keep the "program" simple and focus on the asynchronous patterns. I wonder whether should have two examples to show the two styles of outer code? One using try/await main()/catch (in order processing) and one using main().then().catch() (out of order processing). They felt quite different to me when I first used async. The command parser could be the same (copy/paste). |
Hi there! 👋
First off, thanks for maintaining such an awesome library! Commander.js has been my go-to for CLI tools for years.
I noticed that while the README mentions using
parseAsync()for async action handlers, there's no complete example showing how to properly handle errors in async contexts. This is a pretty common pain point for developers new to the library.This PR adds an example that demonstrates:
--retryflagparseAsync()is important (with.catch()handler)Example usage:
The example is designed to be:
I'm open to any feedback or changes you'd prefer! 😊
Thanks for considering!