-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement better errors using thiserror
- Loading branch information
1 parent
36d1c1d
commit 12928cf
Showing
5 changed files
with
117 additions
and
48 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -30,3 +30,4 @@ serial_test = "3.0.0" | |
time = "0.3.34" | ||
once_cell = "1.19.0" | ||
dotenvy = "0.15.7" | ||
thiserror = "1.0" |
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,28 @@ | ||
use poise::serenity_prelude as serenity; | ||
use thiserror::Error; | ||
|
||
pub type Result<T> = std::result::Result<T, Error>; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum Error { | ||
/// TODO: Actually put a meaningful error in here. | ||
/// needs integration with the mysql_lib module. | ||
#[error("Error with the database, check logs")] | ||
Database, | ||
#[error("Serenity error")] | ||
Serenity(#[from] serenity::Error), | ||
#[error("You are not part of a semester study group")] | ||
UserIsMissingSemesterStudyGroup, | ||
#[error("Invalid subject id: {0}")] | ||
InvalidSubjectId(i32), | ||
#[error("Invalid subject name: {0}")] | ||
InvalidSubjectName(String), | ||
} | ||
|
||
impl Error { | ||
/// This can match on specific error types, so that they can be formatted using | ||
/// discord-specific formatting options. | ||
pub fn create_reply(&self) -> poise::CreateReply { | ||
poise::CreateReply::default().content(self.to_string()).reply(true) | ||
} | ||
} |
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