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:
parent
418d68de49
commit
41c060d7d0
3 changed files with 5 additions and 4 deletions
|
@ -50,7 +50,7 @@ impl FromStr for DiarioArgs {
|
||||||
DiarioArgs { warning, quote, quoted, context }
|
DiarioArgs { warning, quote, quoted, context }
|
||||||
}
|
}
|
||||||
None => {
|
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 warning = None;
|
||||||
let quote = s.to_string();
|
let quote = s.to_string();
|
||||||
|
|
|
@ -151,11 +151,11 @@ impl Command {
|
||||||
Ok(())
|
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::debug!("Received a malformed command: {:?}", message.text());
|
||||||
|
|
||||||
log::trace!("Sending error message...");
|
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
|
let _reply = bot
|
||||||
.send_message(message.chat.id, text)
|
.send_message(message.chat.id, text)
|
||||||
.reply_parameters(ReplyParameters::new(message.id))
|
.reply_parameters(ReplyParameters::new(message.id))
|
||||||
|
|
|
@ -138,7 +138,8 @@ impl TelegramService {
|
||||||
}
|
}
|
||||||
Err(ParseError::IncorrectFormat(e)) => {
|
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.");
|
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.")?;
|
.context("Impossibile gestire comando malformato complesso.")?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue