rsfdisk/
error.rs

1// Copyright (c) 2023 Nick Piaddo
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3
4//! Library-level error module.
5
6// From dependency library
7use thiserror::Error;
8
9// From standard library
10
11// From this library
12use crate::core::errors::ConversionError;
13use crate::core::errors::GenIteratorError;
14use crate::core::errors::HeaderEntryContentError;
15use crate::core::errors::ParserError;
16use crate::core::errors::PartitionBuilderError;
17use crate::core::errors::PartitionError;
18use crate::core::errors::PartitionIterError;
19use crate::core::errors::PartitionKindBuilderError;
20use crate::core::errors::PartitionKindError;
21use crate::core::errors::PartitionListError;
22use crate::core::errors::PartitionTableError;
23use crate::core::errors::PromptError;
24use crate::core::errors::ScriptError;
25
26use crate::fdisk::FdiskBuilderError;
27use crate::fdisk::FdiskError;
28
29use crate::core::utils::version::VersionError;
30
31/// A specialized [`Result`](std::result::Result) type for `rsfdisk`.
32///
33/// This typedef is generally used at the program-level to avoid writing out [`RsFdiskError`]
34/// directly, and is, otherwise, a direct mapping to [`Result`](std::result::Result).
35#[allow(dead_code)]
36pub type Result<T> = std::result::Result<T, RsFdiskError>;
37
38/// Library-level runtime errors.
39///
40/// This enum includes all variants of error types susceptible to occur in the library. Other, more
41/// granular error types, are automatically converted to an `RsFdiskError` when needed.
42///
43/// # Examples
44/// ----
45///
46/// ```
47/// fn main() -> rsfdisk::Result<()> {
48///
49///     Ok(())
50/// }
51/// ```
52#[derive(Debug, Error, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
53#[non_exhaustive]
54pub enum RsFdiskError {
55    #[error(transparent)]
56    Conversion(#[from] ConversionError),
57
58    #[error(transparent)]
59    Fdisk(#[from] FdiskError),
60
61    #[error(transparent)]
62    FdiskBuilder(#[from] FdiskBuilderError),
63
64    #[error(transparent)]
65    GenIterator(#[from] GenIteratorError),
66
67    #[error(transparent)]
68    HeaderEntryContent(#[from] HeaderEntryContentError),
69
70    #[error(transparent)]
71    Parser(#[from] ParserError),
72
73    #[error(transparent)]
74    Partition(#[from] PartitionError),
75
76    #[error(transparent)]
77    PartitionBuilder(#[from] PartitionBuilderError),
78
79    #[error(transparent)]
80    PartitionIter(#[from] PartitionIterError),
81
82    #[error(transparent)]
83    PartitionKind(#[from] PartitionKindError),
84
85    #[error(transparent)]
86    PartitionKindBuilder(#[from] PartitionKindBuilderError),
87
88    #[error(transparent)]
89    PartitionList(#[from] PartitionListError),
90
91    #[error(transparent)]
92    PartitionTable(#[from] PartitionTableError),
93
94    #[error(transparent)]
95    Prompt(#[from] PromptError),
96
97    #[error(transparent)]
98    Script(#[from] ScriptError),
99
100    #[error(transparent)]
101    Version(#[from] VersionError),
102}