Conversation
0b25406 to
70ccdba
Compare
a9ca592 to
916858c
Compare
916858c to
59b9cef
Compare
0c1e534 to
b6f47ea
Compare
|
I've just tested it manually, seems to work well. We should figure out how best to handle errors when for example the user has no study group role - I'd like to avoid replying to the user on discord in every function / when anything fails, as we'd need the context in every function, so it would be nice if we could have either some generic error (like the Errors thrown by a command function can be caught using an on_error handler (this can do much more, like catch command panics, btw). This means that we can use either of the options - I've tried out miette, and it works beautifully. We need to add the dependency, add a simple error handler (~40 lines of code, because I've added a lot of information), and whenever we want to return an error (that the user should see), we simply do |
I think the best would be to define our own errors (in an error module) and then handle them in Edit: for inspiration one can look at how it was done in the python version: https://github.com/marcelropos/HM-DiscordBot/tree/master/core/error |
|
I'm gonna guess that this is done so that individual errors can report their own information in a customizable way, with discord-specific ways of formatting? Also, I think the best way to implement this (with the above presumption) is to use thiserror to get a |
Yes exactly.
Yes sound goods |
|
Alright - is it okay if I put this in the scope of this pr? Would be good if I had error handling, and with thiserror, I don't think it's that much work |
|
Yes put it in here |
maxwai
left a comment
There was a problem hiding this comment.
just a quick review from the diff. Still need to do local testing and to actually look into the subject.rs file
| 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) | ||
| } |
There was a problem hiding this comment.
The error reply should look similar to the old error reply (of course not 1:1). So the errors should have following fields in an embed:
- Command
- Cause
- Solution
- as a footer the command author and current time
Also, the possibility, if needed, to write something outside of the embed. (Often used for pings)
An Example how it currently looks like:
Of course this may go over the scope of the PR so let me know how you want to handle this. I could implement it in another PR, leaving this implementation for now or I could also implement it in this PR directy. Or you may event implement it if you want.
There was a problem hiding this comment.
I think it's fine to implement it here because there's not a lot of development going on outside this, and the changes here aren't needed for other pr's right now. You can implement it in here if you want to, I'm not sure I know what would be best for users, which is 90% of the implementation.

Implements #180 #181 #182 #183 #184
TODO: