1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-21 18:44:19 +00:00

Improve error messages for custom parsing failures

This commit is contained in:
Steffo 2024-08-25 12:57:33 +02:00
parent 418d68de49
commit 41c060d7d0
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
3 changed files with 5 additions and 4 deletions

View file

@ -50,7 +50,7 @@ impl FromStr for DiarioArgs {
DiarioArgs { warning, quote, quoted, context }
}
None => {
anyhow::ensure!(!s.is_empty(), "La citazione specificata non deve essere vuota.");
anyhow::ensure!(!s.is_empty(), "la citazione non deve essere vuota.");
let warning = None;
let quote = s.to_string();

View file

@ -151,11 +151,11 @@ impl Command {
Ok(())
}
pub async fn handle_malformed_complex(bot: Bot, message: Message) -> CommandResult {
pub async fn handle_malformed_complex(bot: &Bot, message: &Message, error: &Error) -> CommandResult {
log::debug!("Received a malformed command: {:?}", message.text());
log::trace!("Sending error message...");
let text = "⚠️ Il comando si aspetta una sintassi diversa da quella che ha ricevuto.";
let text = format!("⚠️ Sintassi del comando errata: {error}");
let _reply = bot
.send_message(message.chat.id, text)
.reply_parameters(ReplyParameters::new(message.id))

View file

@ -138,7 +138,8 @@ impl TelegramService {
}
Err(ParseError::IncorrectFormat(e)) => {
log::debug!("Message text is a command with a custom format, but the parser returned the error {e:?}; handling as a malformed command.");
Command::handle_malformed_complex(bot, message).await
let error = anyhow::format_err!(e);
Command::handle_malformed_complex(&bot, &message, &error).await
.context("Impossibile gestire comando malformato complesso.")?;
return Ok(());
}