How To Wrap Your Errors With Enums When Using Error-Stack

<p>I am an intermediate Rust developer, and you may know me from my posts on subreddits like&nbsp;<a href="https://reddit.com/r/opensource" rel="noopener ugc nofollow" target="_blank">r/opensource</a>&nbsp;or&nbsp;<a href="https://reddit.com/r/rust" rel="noopener ugc nofollow" target="_blank">r/rust</a>&nbsp;or from my various projects on GitHub.</p> <p>Recently, we decided to do error handling and provide custom error messages for the errors related to each engine code present under the&nbsp;<code>src/engines</code>&nbsp;folder in one of my project&rsquo;s,&nbsp;<a href="https://github.com/neon-mmd/websurfx" rel="noopener ugc nofollow" target="_blank">websurfx</a>, when using error-stack. We wanted to use enums for it, and we found that the error-stack project provided no guide, tutorial, or examples. But one of our maintainers,&nbsp;<a href="https://github.com/xffxff" rel="noopener ugc nofollow" target="_blank">@xffxff</a>, provided a cool solution to this problem that helped me learn much, so I decided to share it with you all. You&rsquo;ll learn how you can wrap errors with enums when using error-stack, so stick around until the end of the article.</p> <p>&nbsp;</p> <p><a href="https://www.pexels.com/photo/a-person-trimming-a-wood-plank-with-and-edge-1-6654031/" rel="noopener ugc nofollow" target="_blank">Image by cottonbro on Pexels</a></p> <p>For this tutorial, I will be writing a simple scraping program to scrape the&nbsp;<a href="https://example.com/" rel="noopener ugc nofollow" target="_blank">example.com</a>&nbsp;webpage, and then we will write code to handle errors with enums based on it. Let&rsquo;s dive straight into it.</p> <h1>Simple Scraping Program</h1> <p>Let&rsquo;s first start by explaining the code I have written to scrape the&nbsp;<code>More information href link</code>&nbsp;in the&nbsp;<a href="https://example.com/" rel="noopener ugc nofollow" target="_blank">example.com</a>&nbsp;webpage. We will use it throughout the program to write the&nbsp;<code>error-handling</code>&nbsp;code for it.</p> <p><a href="https://betterprogramming.pub/how-to-wrap-your-errors-with-enums-when-using-error-stack-77b122016e6e">Read More</a></p>
Tags: Enums Wrap