-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
38 changed files
with
423 additions
and
648 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//! | ||
//! # Handling Errors with CommandsAggregator | ||
//! | ||
//! This module provides an example of how to use `wca::CommandsAggregator` to manage error handling in a command-line interface. The `CommandsAggregator` offers a fluent interface for defining commands and associating them with various error types, making it straightforward to handle and present errors in a structured way. | ||
//! | ||
//! ## Purpose | ||
//! | ||
//! The primary goal of this example is to showcase how `CommandsAggregator` facilitates error handling, whether errors are simple strings, custom typed errors, untyped errors, or errors with additional context. This approach ensures that error management is both consistent and extensible. | ||
//! | ||
#[ derive( Debug, error_tools::typed::Error )] | ||
enum CustomError | ||
{ | ||
#[ error( "this is typed error" ) ] | ||
TheError, | ||
} | ||
|
||
fn main() -> error_tools::error::untyped::Result< () > | ||
{ | ||
let ca = wca::CommandsAggregator::former() | ||
.command( "error.string" ) | ||
.hint( "Returns error as a string" ) | ||
.routine( || { Err( "this is string error" ) } ) | ||
.end() | ||
.command( "error.typed" ) | ||
.hint( "Returns error as a custom error" ) | ||
.routine( || { Err( CustomError::TheError ) } ) | ||
.end() | ||
.command( "error.untyped" ) | ||
.hint( "Returns error as untyped error" ) | ||
.routine( || { Err( error_tools::error::untyped::format_err!( "this is untyped error" ) ) } ) | ||
.end() | ||
.command( "error.with_context" ) | ||
.hint( "Returns error as untyped error with context" ) | ||
.routine( || { Err( error_tools::error::untyped::format_err!( "this is untyped error" ).context( "with context" ) ) } ) | ||
.end() | ||
.perform(); | ||
|
||
let args: Vec< String > = std::env::args().skip( 1 ).collect(); | ||
() = ca.perform( args )?; | ||
|
||
Ok( () ) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.