artifactize_core/verify_tools/
error.rs1use super::page::CursorError;
3use crate::config::ConfigError;
4use std::fmt;
5
6#[derive(Debug)]
7pub enum ArgumentsError {
8 ProjectRelative,
9 ProjectType,
10 UnknownTool(String),
11 Decode(serde_json::Error),
12 CursorType,
13 ConflictingWait,
14 Cursor(CursorError),
15 ToolOptions(String),
16 LogOptions(String),
17}
18
19impl fmt::Display for ArgumentsError {
20 fn fmt(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result {
21 match self {
22 Self::ProjectRelative => out.write_str("project must be an absolute folder."),
23 Self::ProjectType => out.write_str("Invalid arguments: project must be a string."),
24 Self::UnknownTool(name) => write!(out, "Unknown tool: {name}"),
25 Self::Decode(error) => write!(out, "Invalid arguments: {error}"),
26 Self::ConflictingWait => {
27 out.write_str("wait_for_action and seconds cannot be combined.")
28 }
29 Self::CursorType => out.write_str("cursor must be a string"),
30 Self::Cursor(error) => error.fmt(out),
31 Self::ToolOptions(message) | Self::LogOptions(message) => out.write_str(message),
32 }
33 }
34}
35
36#[derive(Debug)]
37pub enum Error {
38 Arguments(ArgumentsError),
39 Config(ConfigError),
40 Operation(String),
41 CredentialInventory,
42 RequestOutsideProject,
43 Encode(serde_json::Error),
44 Cursor(CursorError),
45}
46
47impl fmt::Display for Error {
48 fn fmt(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result {
49 match self {
50 Self::Arguments(error) => error.fmt(out),
51 Self::Config(error) => error.fmt(out),
52 Self::Operation(message) => out.write_str(message),
53 Self::CredentialInventory => {
54 out.write_str("Cannot read the managed credential inventory.")
55 }
56 Self::RequestOutsideProject => out.write_str("Request not found in this repository."),
57 Self::Encode(error) => error.fmt(out),
58 Self::Cursor(error) => error.fmt(out),
59 }
60 }
61}
62
63impl From<String> for Error {
65 fn from(message: String) -> Self {
66 Self::Operation(message)
67 }
68}
69
70impl From<serde_json::Error> for Error {
71 fn from(error: serde_json::Error) -> Self {
72 Self::Encode(error)
73 }
74}