From 4d81cb1880b2d3ca71dd3390add0d7f924ad84a9 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 8 Dec 2025 05:31:43 +0900 Subject: [PATCH] MpdError: impl thiserror --- src/response.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/response.rs b/src/response.rs index fb078f9..699c9b3 100644 --- a/src/response.rs +++ b/src/response.rs @@ -1,4 +1,7 @@ +use std::fmt::Display; + use serde::{Deserialize, Serialize}; +use thiserror::Error; pub type Response = Result<(), MpdError>; @@ -22,10 +25,20 @@ pub enum ErrorCode { Exist = 56, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Error, Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct MpdError { code: ErrorCode, command: String, message: String, command_list_num: usize, } + +impl Display for MpdError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "MPD Error (code: {:?}, command: '{}', message: '{}', command_list_num: {})", + self.code, self.command, self.message, self.command_list_num + ) + } +}