* [pbs-devel] [PATCH vma-to-pbs] improve error message for unexpected end of VMA file
@ 2024-12-17 15:17 Filip Schauer
2025-02-06 14:20 ` [pbs-devel] applied: " Wolfgang Bumiller
0 siblings, 1 reply; 2+ messages in thread
From: Filip Schauer @ 2024-12-17 15:17 UTC (permalink / raw)
To: pbs-devel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* [pbs-devel] applied: [PATCH vma-to-pbs] improve error message for unexpected end of VMA file
2024-12-17 15:17 [pbs-devel] [PATCH vma-to-pbs] improve error message for unexpected end of VMA file Filip Schauer
@ 2025-02-06 14:20 ` Wolfgang Bumiller
0 siblings, 0 replies; 2+ messages in thread
From: Wolfgang Bumiller @ 2025-02-06 14:20 UTC (permalink / raw)
To: Filip Schauer; +Cc: pbs-devel
applied, thanks
On Tue, Dec 17, 2024 at 04:17:01PM +0100, Filip Schauer wrote:
> 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
>
>
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-02-06 14:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-17 15:17 [pbs-devel] [PATCH vma-to-pbs] improve error message for unexpected end of VMA file Filip Schauer
2025-02-06 14:20 ` [pbs-devel] applied: " Wolfgang Bumiller
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal