From: Gabriel Goller <g.goller@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox v2] schema: beautify parameter error output
Date: Mon, 23 Oct 2023 09:57:24 +0200 [thread overview]
Message-ID: <20231023075724.33737-1-g.goller@proxmox.com> (raw)
If there is only one error, output in a single line, without any
excessive newlines at the end. If there are multiple errors, show them
in a bulleted list.
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
proxmox-schema/src/schema.rs | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/proxmox-schema/src/schema.rs b/proxmox-schema/src/schema.rs
index f087706..21b9d8a 100644
--- a/proxmox-schema/src/schema.rs
+++ b/proxmox-schema/src/schema.rs
@@ -101,14 +101,18 @@ impl fmt::Display for ParameterError {
let mut msg = String::new();
if !self.is_empty() {
- msg.push_str("parameter verification errors\n\n");
- }
-
- for (name, err) in self.error_list.iter() {
- let _ = writeln!(msg, "parameter '{}': {}", name, err);
+ if self.len() == 1 {
+ msg.push_str("parameter verification failed - ");
+ let _ = write!(msg, "'{}': {}", self.error_list[0].0, self.error_list[0].1);
+ } else {
+ msg.push_str("parameter verification failed:\n");
+ for (name, err) in self.error_list.iter() {
+ let _ = writeln!(msg, "- '{}': {}", name, err);
+ }
+ }
}
- write!(f, "{}", msg)
+ write!(f, "{}", msg.trim())
}
}
--
2.39.2
next reply other threads:[~2023-10-23 7:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-23 7:57 Gabriel Goller [this message]
2023-10-23 15:40 ` [pbs-devel] applied: " Thomas Lamprecht
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=20231023075724.33737-1-g.goller@proxmox.com \
--to=g.goller@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 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.