|
| 1 | +//! Module d'erreurs personnalisées pour GSP |
| 2 | +//! |
| 3 | +//! Ce module définit les types d'erreurs utilisés dans l'ensemble du projet. |
| 4 | +
|
| 5 | +use std::fmt; |
| 6 | +use std::io; |
| 7 | + |
| 8 | +/// Type d'erreur personnalisé pour GSP |
| 9 | +#[derive(Debug)] |
| 10 | +#[allow(dead_code)] |
| 11 | +pub enum GspError { |
| 12 | + /// Erreur lors de la récupération du texte |
| 13 | + TextRetrieval(String), |
| 14 | + /// Erreur d'entrée/sortie |
| 15 | + Io(io::Error), |
| 16 | + /// Erreur de traduction |
| 17 | + Translation(String), |
| 18 | + /// Erreur TTS (Text-To-Speech) |
| 19 | + Tts(String), |
| 20 | + /// Erreur de processus |
| 21 | + Process(String), |
| 22 | + /// Erreur de fichier |
| 23 | + File(String), |
| 24 | + /// Erreur de configuration |
| 25 | + Config(String), |
| 26 | +} |
| 27 | + |
| 28 | +impl fmt::Display for GspError { |
| 29 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 30 | + match self { |
| 31 | + GspError::TextRetrieval(msg) => write!(f, "Erreur de récupération de texte: {}", msg), |
| 32 | + GspError::Io(err) => write!(f, "Erreur I/O: {}", err), |
| 33 | + GspError::Translation(msg) => write!(f, "Erreur de traduction: {}", msg), |
| 34 | + GspError::Tts(msg) => write!(f, "Erreur TTS: {}", msg), |
| 35 | + GspError::Process(msg) => write!(f, "Erreur de processus: {}", msg), |
| 36 | + GspError::File(msg) => write!(f, "Erreur de fichier: {}", msg), |
| 37 | + GspError::Config(msg) => write!(f, "Erreur de configuration: {}", msg), |
| 38 | + } |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +impl std::error::Error for GspError {} |
| 43 | + |
| 44 | +impl From<io::Error> for GspError { |
| 45 | + fn from(err: io::Error) -> Self { |
| 46 | + GspError::Io(err) |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +/// Alias de Result utilisant GspError |
| 51 | +pub type GspResult<T> = Result<T, GspError>; |
0 commit comments