parallel_disk_usage/
runtime_error.rs1use derive_more::{Display, Error};
2use std::{convert::Infallible, process::ExitCode};
3
4#[derive(Debug, Display, Error)]
6#[non_exhaustive]
7pub enum RuntimeError {
8 #[display("SerializationFailure: {_0}")]
11 SerializationFailure(serde_json::Error),
12 #[display("DeserializationFailure: {_0}")]
15 DeserializationFailure(serde_json::Error),
16 #[display("JsonInputArgConflict: Arguments exist alongside --json-input")]
18 JsonInputArgConflict,
19 #[display("InvalidInputReflection: {_0}")]
21 InvalidInputReflection(#[error(not(source))] String),
22 #[display("UnsupportedFeature: {_0}")]
24 UnsupportedFeature(UnsupportedFeature),
25}
26
27#[derive(Debug, Display, Error)]
29#[non_exhaustive]
30pub enum UnsupportedFeature {
31 #[cfg(not(unix))]
33 #[display("Feature --deduplicate-hardlinks is not available on this platform")]
34 DeduplicateHardlink,
35 #[cfg(not(unix))]
37 #[display("Feature --one-file-system is not available on this platform")]
38 OneFileSystem,
39}
40
41impl From<Infallible> for RuntimeError {
42 fn from(value: Infallible) -> Self {
43 match value {}
44 }
45}
46
47impl RuntimeError {
48 pub fn code(&self) -> ExitCode {
50 ExitCode::from(match self {
51 RuntimeError::SerializationFailure(_) => 2,
52 RuntimeError::DeserializationFailure(_) => 3,
53 RuntimeError::JsonInputArgConflict => 4,
54 RuntimeError::InvalidInputReflection(_) => 5,
55 RuntimeError::UnsupportedFeature(_) => 6,
56 })
57 }
58}