alpm_compress/error.rs
1//! Error handling.
2
3use std::{fmt::Debug, num::TryFromIntError};
4
5use alpm_types::CompressionAlgorithmFileExtension;
6
7use crate::compression::CompressionSettings;
8
9/// An error that can occur when using compression.
10#[derive(Debug, thiserror::Error)]
11pub enum Error {
12 /// An error occurred while creating a Zstandard encoder.
13 #[error(
14 "Error creating a Zstandard encoder while {context} with {compression_settings:?}:\n{source}"
15 )]
16 CreateZstandardEncoder {
17 /// The context in which the error occurred.
18 ///
19 /// This is meant to complete the sentence "Error creating a Zstandard encoder while
20 /// {context} with {compression_settings}".
21 context: &'static str,
22 /// The compression settings chosen for the encoder.
23 compression_settings: CompressionSettings,
24 /// The source error.
25 source: std::io::Error,
26 },
27
28 /// An error occurred while creating a Zstandard decoder.
29 #[error("Error creating a Zstandard decoder:\n{0}")]
30 CreateZstandardDecoder(#[source] std::io::Error),
31
32 /// An error occurred while finishing a compression encoder.
33 #[error("Error while finishing {compression_type} compression encoder:\n{source}")]
34 FinishEncoder {
35 /// The compression chosen for the encoder.
36 compression_type: CompressionAlgorithmFileExtension,
37 /// The source error
38 source: std::io::Error,
39 },
40
41 /// An error occurred while trying to get the available parallelism.
42 #[error("Error while trying to get available parallelism:\n{0}")]
43 GetParallelism(#[source] std::io::Error),
44
45 /// An error occurred while trying to convert an integer.
46 #[error("Error while trying to convert an integer:\n{0}")]
47 IntegerConversion(#[source] TryFromIntError),
48
49 /// An I/O error occurred while reading.
50 #[error("I/O read error while {context}:\n{source}")]
51 IoRead {
52 /// The context in which the error occurred.
53 ///
54 /// This is meant to complete the sentence "I/O read error while ".
55 context: &'static str,
56 /// The source error.
57 source: std::io::Error,
58 },
59
60 /// An I/O error occurred while writing.
61 #[error("I/O write error while {context}:\n{source}")]
62 IoWrite {
63 /// The context in which the error occurred.
64 ///
65 /// This is meant to complete the sentence "I/O write error while ".
66 context: &'static str,
67 /// The source error.
68 source: std::io::Error,
69 },
70
71 /// A compression level is not valid.
72 #[error("Invalid compression level {level} (must be in the range {min} - {max})")]
73 InvalidCompressionLevel {
74 /// The invalid compression level.
75 level: u8,
76 /// The minimum valid compression level.
77 min: u8,
78 /// The maximum valid compression level.
79 max: u8,
80 },
81
82 /// A compression algorithm file extension is not known.
83 #[error("Unknown compression algorithm file extension:\n{0}")]
84 UnknownCompressionAlgorithmFileExtension(#[source] alpm_types::Error),
85
86 /// An unsupported compression algorithm was used.
87 #[error("Unsupported compression algorithm: {value}")]
88 UnsupportedCompressionAlgorithm {
89 /// The unsupported compression algorithm.
90 value: String,
91 },
92}