commit e3d966ac41d9206cbd7c733f9f35114a9b842cdf
parent 16ffa9a2ff3736412af3dd3807a501d37f20f7fc
Author: MTRNord <mtrnord1@gmail.com>
Date: Fri, 8 Jan 2021 14:23:20 +0100
fix: Require a error from the bot to fix issues with error conversion
Diffstat:
6 files changed, 20 insertions(+), 13 deletions(-)
diff --git a/example-bot/Cargo.toml b/example-bot/Cargo.toml
@@ -18,4 +18,5 @@ tracing-subscriber = "0.2"
tracing-futures = "0.2.4"
tokio = { version = "1.0.1", features = ["full"] }
clap = "3.0.0-beta.2"
-async-trait = "0.1.41"
-\ No newline at end of file
+async-trait = "0.1.41"
+thiserror = "1.0"
+\ No newline at end of file
diff --git a/example-bot/src/commands/hello_world.rs b/example-bot/src/commands/hello_world.rs
@@ -1,7 +1,7 @@
+use crate::errors::Error;
use matrix_sdk::events::{room::message::MessageEventContent, AnyMessageEventContent};
use mrsbfh::commands::command;
use mrsbfh::config::Config;
-use std::error::Error;
#[command(help = "`!hello_world` - Prints \"hello world\".")]
pub async fn hello_world<C: Config>(
@@ -9,7 +9,7 @@ pub async fn hello_world<C: Config>(
_config: C,
_sender: String,
mut _args: Vec<&str>,
-) -> Result<(), Box<dyn Error>> {
+) -> Result<(), Error> {
let content =
AnyMessageEventContent::RoomMessage(MessageEventContent::notice_plain("Hello World!"));
diff --git a/example-bot/src/commands/mod.rs b/example-bot/src/commands/mod.rs
@@ -1,11 +1,9 @@
+use crate::errors::Error;
use mrsbfh::commands::command_generate;
pub mod hello_world;
-#[command_generate(
- bot_name = "Example",
- description = "This bot prints hello!"
-)]
+#[command_generate(bot_name = "Example", description = "This bot prints hello!")]
enum Commands {
- HelloWorld
-}
-\ No newline at end of file
+ HelloWorld,
+}
diff --git a/example-bot/src/errors.rs b/example-bot/src/errors.rs
@@ -0,0 +1,8 @@
+use matrix_sdk::events::AnyMessageEventContent;
+use thiserror::Error as ThisError;
+
+#[derive(ThisError, Debug)]
+pub enum Error {
+ #[error(transparent)]
+ SendError(#[from] tokio::sync::mpsc::error::SendError<AnyMessageEventContent>),
+}
diff --git a/example-bot/src/main.rs b/example-bot/src/main.rs
@@ -6,6 +6,7 @@ use tracing::*;
pub mod commands;
mod config;
+mod errors;
mod matrix;
#[derive(Clap)]
diff --git a/mrsbfh-macros/src/lib.rs b/mrsbfh-macros/src/lib.rs
@@ -133,7 +133,7 @@ pub fn command_generate(args: TokenStream, input: TokenStream) -> TokenStream {
async fn help(
mut tx: mrsbfh::Sender,
- ) -> Result<(), std::boxed::Box<dyn std::error::Error>> {
+ ) -> Result<(), Error> {
let options = mrsbfh::pulldown_cmark::Options::empty();
let parser = mrsbfh::pulldown_cmark::Parser::new_ext(HELP_MARKDOWN, options);
let mut html = String::new();
@@ -156,7 +156,7 @@ pub fn command_generate(args: TokenStream, input: TokenStream) -> TokenStream {
Ok(())
}
- pub async fn match_command<C: mrsbfh::config::Config>(cmd: &str, config: C, tx: mrsbfh::Sender, sender: String, args: Vec<&str>,) -> Result<(), std::boxed::Box<dyn std::error::Error>> {
+ pub async fn match_command<C: mrsbfh::config::Config>(cmd: &str, config: C, tx: mrsbfh::Sender, sender: String, args: Vec<&str>,) -> Result<(), Error> {
match cmd {
#(#commands)*
"help" => {