cpp-linter / cpp-linter-rs

A CLI tool that scans a batch of files with clang-tidy and/or clang-format, then provides feedback in the form of comments, annotations, summaries, and reviews.
https://cpp-linter.github.io/cpp-linter-rs/
MIT License
1 stars 0 forks source link

propagate panics as errors to callers #35

Closed 2bndy5 closed 2 months ago

2bndy5 commented 2 months ago

Currently, there are a lot of places where I use Result.expect() to panic on unexpected behavior. Most notably in RestApiClient.send_api_request(). It is more idiomatic rust to handle errors in the caller instead of arbitrarily throwing panics.

This solution may be considered a refactor since there are so many instances where the code calls Result.expect(), or Result.unwrap() (same as .expect() but without customized error message).

[!note] There are some instances where it makes sense to use .unwrap(), but it should be determined by the code block's local context.

TBH, this problem was born from the fact that this is my first rust project. I should have picked a more robust design from the start.