Skip to content

Commit eb0253d

Browse files
authored
address error documentation lint (#641)
1 parent 64dde98 commit eb0253d

File tree

5 files changed

+70
-6
lines changed

5 files changed

+70
-6
lines changed

src/image.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ pub struct Block {
6363
}
6464

6565
impl Header {
66+
/// Reads a header from the provided file.
67+
///
68+
/// # Errors
69+
/// Returns an error if:
70+
/// - The header cannot be read from the file
71+
/// - The magic number or version is invalid
72+
/// - The padding value is not zero
6673
pub fn read(mut src: &File) -> Result<Self> {
6774
let magic = src
6875
.read_u32::<LittleEndian>()
@@ -105,6 +112,12 @@ impl Header {
105112
Ok(bytes)
106113
}
107114

115+
/// Writes the header to the destination writer.
116+
///
117+
/// # Errors
118+
/// Returns an error if:
119+
/// - The version is not supported
120+
/// - The header cannot be written to the destination
108121
pub fn write<W>(&self, dst: &mut W) -> Result<()>
109122
where
110123
W: Write,
@@ -115,6 +128,12 @@ impl Header {
115128
}
116129
}
117130

131+
/// Copies data from a source reader to a destination writer.
132+
///
133+
/// # Errors
134+
/// Returns an error if:
135+
/// - Reading from the source fails
136+
/// - Writing to the destination fails
118137
pub fn copy<R, W>(mut size: usize, src: &mut R, dst: &mut W) -> Result<()>
119138
where
120139
R: Read,
@@ -220,6 +239,13 @@ where
220239
}
221240
}
222241

242+
/// Copies a memory block from the source reader to the destination writer.
243+
///
244+
/// # Errors
245+
/// Returns an error if:
246+
/// - Reading from the source fails
247+
/// - Writing to the destination fails
248+
/// - Size conversion from u64 to usize fails
223249
pub fn copy_block<R, W>(mut header: Header, src: &mut R, dst: &mut W) -> Result<()>
224250
where
225251
R: Read,
@@ -277,6 +303,12 @@ impl Image {
277303
.map_err(Error::Write)
278304
}
279305

306+
/// Creates a new Image with the specified version, source filename, and destination filename.
307+
///
308+
/// # Errors
309+
/// Returns an error if:
310+
/// - The source file cannot be opened for reading
311+
/// - The destination file cannot be created or opened for writing
280312
pub fn new(version: u32, src_filename: &Path, dst_filename: &Path) -> Result<Self> {
281313
let src = OpenOptions::new()
282314
.read(true)
@@ -288,6 +320,10 @@ impl Image {
288320
Ok(Self { version, src, dst })
289321
}
290322

323+
/// Writes multiple memory blocks to the destination file.
324+
///
325+
/// # Errors
326+
/// Returns an error if writing any block fails
291327
pub fn write_blocks(&mut self, blocks: &[Block]) -> Result<()> {
292328
for block in blocks {
293329
self.write_block(block)

src/iomem.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@ use std::{fs::read_to_string, io::Error as IoError, path::Path};
88
pub enum Error {
99
#[error("unable to read from /proc/iomem")]
1010
Io(#[from] IoError),
11-
1211
#[error("unable to parse value")]
1312
Parse(#[from] ParseIntError),
14-
1513
#[error("unable to parse line: {0}")]
1614
ParseLine(String),
17-
1815
#[error("need CAP_SYS_ADMIN to read /proc/iomem")]
1916
PermissionDenied,
2017
}
2118

2219
/// Parse /proc/iomem and return System RAM memory ranges
20+
///
21+
/// # Errors
22+
/// Returns an error if:
23+
/// - Failed to read the /proc/iomem file
24+
/// - Failed to parse memory ranges from the file content
25+
/// - Permission denied when trying to read /proc/iomem (requires `CAP_SYS_ADMIN`)
2326
pub fn parse() -> Result<Vec<Range<u64>>, Error> {
2427
parse_file(Path::new("/proc/iomem"))
2528
}

src/snapshot.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,23 @@ impl<'a, 'b> Snapshot<'a, 'b> {
208208
}
209209

210210
fn create_source(&self, src: &Source) -> Result<()> {
211-
match src {
211+
match *src {
212212
Source::ProcKcore => self.kcore(),
213213
Source::DevCrash => self.phys(Path::new("/dev/crash")),
214214
Source::DevMem => self.phys(Path::new("/dev/mem")),
215-
Source::Raw(s) => self.phys(s),
215+
Source::Raw(ref s) => self.phys(s),
216216
}
217217
.map_err(|e| Error::UnableToCreateSnapshotFromSource(Box::new(e), src.clone()))
218218
}
219219

220220
/// Create a memory snapshot
221+
///
222+
/// # Errors
223+
/// Returns an error if:
224+
/// - No source is available for creating the snapshot
225+
/// - There is a failure reading from the specified source
226+
/// - The estimated disk usage exceeds the specified limits
227+
/// - Failed to create or write to the destination file
221228
pub fn create(&self) -> Result<()> {
222229
if let Some(src) = self.source {
223230
self.create_source(src)?;

src/upload/blobstore.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ pub struct BlobUploader {
170170
}
171171

172172
impl BlobUploader {
173+
/// Create a new ``BlobUploader`` from a SAS URL.
174+
///
175+
/// # Errors
176+
/// Returns an error if:
177+
/// - The URL cannot be parsed as a valid Azure SAS URL
173178
pub fn new(sas: &Url) -> Result<Self> {
174179
let blob_client = BlobClient::from_sas_url(sas)?;
175180
Ok(Self::with_blob_client(blob_client))
@@ -222,9 +227,16 @@ impl BlobUploader {
222227
}
223228

224229
/// Upload a file to Azure Blob Store using a fully qualified SAS token
230+
///
231+
/// # Errors
232+
/// Returns an error if:
233+
/// - The file cannot be opened or read
234+
/// - The file size cannot be converted to a usize
235+
/// - The file is too large for Azure Blob Storage
236+
/// - There is a failure during the upload process
237+
/// - There is a failure finalizing the block list
225238
pub async fn upload_file(mut self, filename: &Path) -> Result<()> {
226239
let file = File::open(filename).await?;
227-
228240
let file_size = file
229241
.metadata()
230242
.await?

src/upload/http.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ pub enum Error {
2222
}
2323

2424
/// Upload a file via HTTP PUT
25+
///
26+
/// # Errors
27+
/// Returns an error if:
28+
/// - The file cannot be opened or read
29+
/// - There is a failure making the HTTP request
30+
/// - The server returns an unexpected status code
2531
#[cfg(feature = "put")]
2632
pub async fn put(filename: &Path, url: &Url) -> Result<(), Error> {
2733
let file = File::open(&filename)

0 commit comments

Comments
 (0)