dm_database_sqllog2db/
error.rs1use std::io;
2use std::path::PathBuf;
3use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
6
7#[derive(Debug, Error)]
8pub enum Error {
9 #[error("Configuration error: {0}")]
10 Config(#[from] ConfigError),
11
12 #[error("File error: {0}")]
13 File(#[from] FileError),
14
15 #[error("SQL log parser error: {0}")]
16 Parser(#[from] ParserError),
17
18 #[error("Export error: {0}")]
19 Export(#[from] ExportError),
20
21 #[error("Update error: {0}")]
22 Update(#[from] UpdateError),
23
24 #[error("IO error: {0}")]
25 Io(#[from] io::Error),
26}
27
28#[derive(Debug, Error)]
29pub enum UpdateError {
30 #[error("Update failed: {0}")]
31 UpdateFailed(String),
32
33 #[error("Check for updates failed: {0}")]
34 CheckFailed(String),
35}
36
37#[derive(Debug, Error)]
38pub enum ConfigError {
39 #[error("Configuration file not found: {0}")]
40 NotFound(PathBuf),
41
42 #[error("Failed to parse configuration file {path}: {reason}")]
43 ParseFailed { path: PathBuf, reason: String },
44
45 #[error("Invalid log level '{level}', valid values: {}", valid_levels.join(", "))]
46 InvalidLogLevel {
47 level: String,
48 valid_levels: Vec<String>,
49 },
50
51 #[error("Invalid configuration value {field} = '{value}': {reason}")]
52 InvalidValue {
53 field: String,
54 value: String,
55 reason: String,
56 },
57
58 #[error("At least one exporter must be configured (csv/jsonl/sqlite)")]
59 NoExporters,
60}
61
62#[derive(Debug, Error)]
63pub enum FileError {
64 #[error("File already exists: {path} (set overwrite=true to replace)")]
65 AlreadyExists { path: PathBuf },
66
67 #[error("Failed to write file {path}: {reason}")]
68 WriteFailed { path: PathBuf, reason: String },
69
70 #[error("Failed to create directory {path}: {reason}")]
71 CreateDirectoryFailed { path: PathBuf, reason: String },
72}
73
74#[derive(Debug, Error)]
75pub enum ParserError {
76 #[error("Path not found: {path}")]
77 PathNotFound { path: PathBuf },
78
79 #[error("Invalid path {path}: {reason}")]
80 InvalidPath { path: PathBuf, reason: String },
81
82 #[error("Failed to read directory {path}: {reason}")]
83 ReadDirFailed { path: PathBuf, reason: String },
84}
85
86#[derive(Debug, Error)]
87#[allow(clippy::enum_variant_names)]
88pub enum ExportError {
89 #[error("Write failed {path}: {reason}")]
91 WriteError { path: PathBuf, reason: String },
92
93 #[cfg(feature = "sqlite")]
95 #[error("Database error: {reason}")]
96 DatabaseError { reason: String },
97}