hrszpuk / rectx

The powerful little project manager for the ReCT programming language!
GNU General Public License v3.0
6 stars 1 forks source link

Custom "bubble up" error handlers for the CLI module #4

Closed hrszpuk closed 2 years ago

hrszpuk commented 2 years ago

Issue

The issue this pull request attempts to resolve is the error messages produced by rectx. Rectx will produce programmer errors (errors that are not easily readable to the average person unless they have knowledge of how Rust and ReCTx works) which even for ReCT programmers may be confusing.

Furthermore, it is possible for many different kinds of errors to be produced by the manager module even if most functions can return a std::io::Error through a Result<T, E> enum.

This pull request should close the issue described in #2.

Solution

This pull request solves the issue above by refactoring the error system. To begin with, the cli module now has a multitude of help functions now:

  1. cli::abort(String): send a message to the user, and calls panic!() clearing the stack and aborting the entire program
  2. cli::issue(String): when a recoverable error is found, message reports the issue to the user.
  3. cli::info(String): this is just for sending non-specific information to the user
  4. cli::process(String): for reporting the beginning of a process to the user
  5. cli::success(Stirng): for reporting a successful result or process to the user

These helper functions are available to every module and allow for future modifications to the error system without major refactoring (like editing every println!.. etc).

The following cli module functions have had their error handling improved through detecting ErrorKind and reporting more specific error messages: