public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup] fix #3921: client: confusing backup reader error
@ 2023-09-01  8:02 Gabriel Goller
  2023-09-01 11:51 ` Thomas Lamprecht
  2023-12-15 12:34 ` Gabriel Goller
  0 siblings, 2 replies; 4+ messages in thread
From: Gabriel Goller @ 2023-09-01  8:02 UTC (permalink / raw)
  To: pbs-devel

When using the catalog shell command, a common error is that user pass
"./files.pxar" instead of "files.pxar". This will result in a cryptic error
"... value does not match regex pattern ...". Added some context to the
error according to suggestions here [1].

[1]: https://bugzilla.proxmox.com/show_bug.cgi?id=3921

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
 pbs-client/src/backup_reader.rs | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/pbs-client/src/backup_reader.rs b/pbs-client/src/backup_reader.rs
index 2cd4dc27..138e836a 100644
--- a/pbs-client/src/backup_reader.rs
+++ b/pbs-client/src/backup_reader.rs
@@ -98,7 +98,10 @@ impl BackupReader {
     pub async fn download<W: Write + Send>(&self, file_name: &str, output: W) -> Result<(), Error> {
         let path = "download";
         let param = json!({ "file-name": file_name });
-        self.h2.download(path, Some(param), output).await
+        self.h2
+            .download(path, Some(param), output)
+            .await
+            .map_err(|err| format_err!("http2 file download '{}' failed: \n{}", file_name, err))
     }
 
     /// Execute a special GET request and send output to a writer
-- 
2.39.2





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [pbs-devel] [PATCH proxmox-backup] fix #3921: client: confusing backup reader error
  2023-09-01  8:02 [pbs-devel] [PATCH proxmox-backup] fix #3921: client: confusing backup reader error Gabriel Goller
@ 2023-09-01 11:51 ` Thomas Lamprecht
  2023-09-01 15:03   ` Gabriel Goller
  2023-12-15 12:34 ` Gabriel Goller
  1 sibling, 1 reply; 4+ messages in thread
From: Thomas Lamprecht @ 2023-09-01 11:51 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Gabriel Goller

Am 01/09/2023 um 10:02 schrieb Gabriel Goller:
> When using the catalog shell command, a common error is that user pass
> "./files.pxar" instead of "files.pxar". This will result in a cryptic error
> "... value does not match regex pattern ...". Added some context to the
> error according to suggestions here [1].

adding error context can be good in general, but the specific case
mentioned could be also solved explicitly by either stripping ./
or handling it explicitly. How does it handle multiple consecutive
slashes in paths? Like "foo///bar"? As that would need similar
normalizing so, if that works, then we maybe got already some place
where we can add handling for ./, and otherwise it might make sense
to start thinking about adding such things.

As when multiple users run into some issue it might be warranted
to check if them "holding it wrong" should be actually a valid way
to hold it.

> 
> [1]: https://bugzilla.proxmox.com/show_bug.cgi?id=3921
> 
> Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
> ---
>  pbs-client/src/backup_reader.rs | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/pbs-client/src/backup_reader.rs b/pbs-client/src/backup_reader.rs
> index 2cd4dc27..138e836a 100644
> --- a/pbs-client/src/backup_reader.rs
> +++ b/pbs-client/src/backup_reader.rs
> @@ -98,7 +98,10 @@ impl BackupReader {
>      pub async fn download<W: Write + Send>(&self, file_name: &str, output: W) -> Result<(), Error> {
>          let path = "download";
>          let param = json!({ "file-name": file_name });
> -        self.h2.download(path, Some(param), output).await
> +        self.h2
> +            .download(path, Some(param), output)
> +            .await
> +            .map_err(|err| format_err!("http2 file download '{}' failed: \n{}", file_name, err))

please use captured identifiers for new format!/format_err! et al.
calls, e.g., here:

.map_err(|err| format_err!("http2 file download '{file_name}' failed - {err}"))

We also normally do not use a newline to separate prefix from actual
error, or would there be a good reason to deviate from the norm here?

>      }
>  
>      /// Execute a special GET request and send output to a writer





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [pbs-devel] [PATCH proxmox-backup] fix #3921: client: confusing backup reader error
  2023-09-01 11:51 ` Thomas Lamprecht
@ 2023-09-01 15:03   ` Gabriel Goller
  0 siblings, 0 replies; 4+ messages in thread
From: Gabriel Goller @ 2023-09-01 15:03 UTC (permalink / raw)
  To: Thomas Lamprecht, Proxmox Backup Server development discussion


On 9/1/23 13:51, Thomas Lamprecht wrote:
> Am 01/09/2023 um 10:02 schrieb Gabriel Goller:
>> When using the catalog shell command, a common error is that user pass
>> "./files.pxar" instead of "files.pxar". This will result in a cryptic error
>> "... value does not match regex pattern ...". Added some context to the
>> error according to suggestions here [1].
> adding error context can be good in general, but the specific case
> mentioned could be also solved explicitly by either stripping ./
> or handling it explicitly. How does it handle multiple consecutive
> slashes in paths? Like "foo///bar"? As that would need similar
> normalizing so, if that works, then we maybe got already some place
> where we can add handling for ./, and otherwise it might make sense
> to start thinking about adding such things.

We return the error above. We have this regex
in place for all file-names:
`PROXMOX_SAFE_ID_REGEX_STR { () => { r"(?:[A-Za-z0-9_][A-Za-z0-9._\-]*)" 
}; }`

> As when multiple users run into some issue it might be warranted
> to check if them "holding it wrong" should be actually a valid way
> to hold it.
I don't think so to be honest, because AFAIK we don't support directories
in snapshots (?) so it doesn't make sense to pass "./test.pxar".

Stripping is also wrong, because the . (dot) would be an accepted character
in the file-name and thus we cannot remove it. Though we could remove every
prohibited character (the / in this case) and the characters around
(the . in our example)?

>> [1]: https://bugzilla.proxmox.com/show_bug.cgi?id=3921
>>
>> Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
>> ---
>>   pbs-client/src/backup_reader.rs | 5 ++++-
>>   1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/pbs-client/src/backup_reader.rs b/pbs-client/src/backup_reader.rs
>> index 2cd4dc27..138e836a 100644
>> --- a/pbs-client/src/backup_reader.rs
>> +++ b/pbs-client/src/backup_reader.rs
>> @@ -98,7 +98,10 @@ impl BackupReader {
>>       pub async fn download<W: Write + Send>(&self, file_name: &str, output: W) -> Result<(), Error> {
>>           let path = "download";
>>           let param = json!({ "file-name": file_name });
>> -        self.h2.download(path, Some(param), output).await
>> +        self.h2
>> +            .download(path, Some(param), output)
>> +            .await
>> +            .map_err(|err| format_err!("http2 file download '{}' failed: \n{}", file_name, err))
> please use captured identifiers for new format!/format_err! et al.
> calls, e.g., here:
>
> .map_err(|err| format_err!("http2 file download '{file_name}' failed - {err}"))
>
> We also normally do not use a newline to separate prefix from actual
> error, or would there be a good reason to deviate from the norm here?
Yes, because the `err` is a multi-line string here. On the api we have a 
`Vec` of errors and return it as a string using `\n`
as a delimiter.
>>       }
>>   
>>       /// Execute a special GET request and send output to a writer




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [pbs-devel] [PATCH proxmox-backup] fix #3921: client: confusing backup reader error
  2023-09-01  8:02 [pbs-devel] [PATCH proxmox-backup] fix #3921: client: confusing backup reader error Gabriel Goller
  2023-09-01 11:51 ` Thomas Lamprecht
@ 2023-12-15 12:34 ` Gabriel Goller
  1 sibling, 0 replies; 4+ messages in thread
From: Gabriel Goller @ 2023-12-15 12:34 UTC (permalink / raw)
  To: pbs-devel

Submitted v2.

On 9/1/23 10:02, Gabriel Goller wrote:
> When using the catalog shell command, a common error is that user pass
> "./files.pxar" instead of "files.pxar". This will result in a cryptic error
> "... value does not match regex pattern ...". Added some context to the
> error according to suggestions here [1].
>
> [1]: https://bugzilla.proxmox.com/show_bug.cgi?id=3921
>
> Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
> ---
>   pbs-client/src/backup_reader.rs | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/pbs-client/src/backup_reader.rs b/pbs-client/src/backup_reader.rs
> index 2cd4dc27..138e836a 100644
> --- a/pbs-client/src/backup_reader.rs
> +++ b/pbs-client/src/backup_reader.rs
> @@ -98,7 +98,10 @@ impl BackupReader {
>       pub async fn download<W: Write + Send>(&self, file_name: &str, output: W) -> Result<(), Error> {
>           let path = "download";
>           let param = json!({ "file-name": file_name });
> -        self.h2.download(path, Some(param), output).await
> +        self.h2
> +            .download(path, Some(param), output)
> +            .await
> +            .map_err(|err| format_err!("http2 file download '{}' failed: \n{}", file_name, err))
>       }
>   
>       /// Execute a special GET request and send output to a writer





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-12-15 12:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-01  8:02 [pbs-devel] [PATCH proxmox-backup] fix #3921: client: confusing backup reader error Gabriel Goller
2023-09-01 11:51 ` Thomas Lamprecht
2023-09-01 15:03   ` Gabriel Goller
2023-12-15 12:34 ` Gabriel Goller

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