public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Filip Schauer <f.schauer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH vma-to-pbs] improve error message for unexpected end of VMA file
Date: Tue, 17 Dec 2024 16:17:01 +0100	[thread overview]
Message-ID: <20241217151701.156187-1-f.schauer@proxmox.com> (raw)

When a VMA file ends unexpectedly while reading the header, change the
error message from "failed to fill whole buffer" to "Unexpected end of
VMA file" for more clarity.

Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
---
 src/vma.rs | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/vma.rs b/src/vma.rs
index 63ee3b5..978e4c7 100644
--- a/src/vma.rs
+++ b/src/vma.rs
@@ -1,4 +1,5 @@
 use std::collections::HashSet;
+use std::io;
 use std::io::Read;
 use std::mem::size_of;
 use std::str;
@@ -126,7 +127,13 @@ impl<T: Read> VmaReader<T> {
 
     fn read_header(vma_file: &mut T) -> Result<VmaHeader, Error> {
         let mut buffer = vec![0; VMA_HEADER_SIZE_NO_BLOB_BUFFER];
-        vma_file.read_exact(&mut buffer)?;
+        vma_file.read_exact(&mut buffer).map_err(|e| {
+            if e.kind() == io::ErrorKind::UnexpectedEof {
+                io::Error::new(io::ErrorKind::UnexpectedEof, "Unexpected end of VMA file")
+            } else {
+                e
+            }
+        })?;
 
         let bincode_options = bincode::DefaultOptions::new()
             .with_fixint_encoding()
@@ -298,9 +305,9 @@ impl<T: Read> VmaReader<T> {
         loop {
             match self.restore_extent(&callback) {
                 Ok(()) => {}
-                Err(e) => match e.downcast_ref::<std::io::Error>() {
+                Err(e) => match e.downcast_ref::<io::Error>() {
                     Some(ioerr) => {
-                        if ioerr.kind() == std::io::ErrorKind::UnexpectedEof {
+                        if ioerr.kind() == io::ErrorKind::UnexpectedEof {
                             break; // Break out of the loop since the end of the file was reached.
                         } else {
                             return Err(format_err!(e)).context("Failed to read VMA file");
-- 
2.39.5



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


                 reply	other threads:[~2024-12-17 15:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241217151701.156187-1-f.schauer@proxmox.com \
    --to=f.schauer@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal