all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: "Gabriel Goller" <g.goller@proxmox.com>
To: "Thomas Lamprecht" <t.lamprecht@proxmox.com>,
	"Proxmox Backup Server development discussion"
	<pbs-devel@lists.proxmox.com>
Subject: Re: [pbs-devel] [PATCH proxmox v5 1/2] router: cli: added `ask_for_confirmation` helper
Date: Thu, 25 Apr 2024 12:37:12 +0200	[thread overview]
Message-ID: <D0T4Z7GOJWRH.1E15N94N7EKZL@proxmox.com> (raw)
In-Reply-To: <3e51c65a-60c3-4846-a480-b5e544e9806b@proxmox.com>

On Thu Apr 25, 2024 at 11:42 AM CEST, Thomas Lamprecht wrote:
> Am 25/04/2024 um 10:52 schrieb Gabriel Goller:
> > On Wed Apr 24, 2024 at 9:03 PM CEST, Thomas Lamprecht wrote:
> >> Am 18/04/2024 um 13:49 schrieb Gabriel Goller:
> >>> +    use regex::Regex;
> >>> +    match default {
> >>> +        DefaultAnswer::Yes => {
> >>> +            // unwrap is okay, because this regex is correct
> >>> +            let no_regex: Regex = Regex::new("^[nN]$").unwrap();
> >>> +            if no_regex.is_match(line.trim()) {
> >>> +                Ok(false)
> >>> +            } else {
> >>> +                Ok(true)
> >>
> >> So, a caller passes DefaultAnswer::Yes, the user enter the full word "no", your logic
> >> then makes it a Yes like it would for all other unrecognized input...  I do not like
> >> such dangerous interfaces, so NACK.
> > 
> > I'd have to disagree, I don't think this is a dangerous interface...
> > If, e.g., we use DefaultAnswer::No, there is no difference between 'no',
> > 'bogus', 'N', or '<enter>' IMO. So why should one return an error and
> > the other one false?
>
> I do think there's a big difference though. Because with "" the user entered
> the empty choice to get the default that was presented to them, with uppercase
> signalling what the default is, and for the others the user entered an unknown,
> invalid choice that one must not derive any action from.
>
> And while yes, as long as the default is a no-op it would be indeed fine to
> silently ignore any bogus input and relay the default answer, but this here
> is a general interface that cannot take such assumptions because it just
> cannot know possibly implications of that choice, the default choice is
> not bound to be the no-op after all.
>
> E.g., if you have an interface that allows for some changes and then could
> sync those to remotes (this is roughly how our CDN repo tooling works).
> It's not a real destructive action and most often syncing is what you want,
> so defaulting to yes is done. But sometimes one must not sync immediately
> due to batching changes or redoing them. Now, what's the better UI for
> following prompt + entry
>
> The proposal of the original patch:
>
> ```
> Sync? [Y/n]: no
> Ok, syncing...
> ```
>
>
> ```
> Sync? [Y/n]: no
> Abort – unexpected choice "no"! Use enter for default or use 'y' or 'n'.
> ```
>
> IMO the latter is much more resilient to human errors, e.g. a middle click
> pasting in some text that contains a newline, or a simple misunderstanding.
> And FWIW also more unlikely, but not unheard of, things like spilling
> drinks, or toddlers or cats walking over the keyboard – which for the
> "accept any invalid input as default answer" has a quite high chance to
> trigger something unexpected.
>
> In short, for confirmation the behavior should be clear and expected,
> accepting arbitrary data as valid choice isn't either; erroring out might
> be a nuisance for some, but is safe and provides clarity.

Ok, you convinced me :)

> > This was just my thought when implementing this, although ultimately,
> > it doesn't matter because we only check for success and ignore errors 
> > and false returns.
> > FWIW I think your implementation is way prettier, especially the Answer
> > enum being input and output :)
> > 
> > Should I apply the diff and submit a new version or can this be applied
> > immediately?
>
> My code was mostly an elaborate sketch, I could be improved a bit, i.e.,
> what I did not really thought through is using std::io::Error as Error type,
> at least for the "invalid input" case it might be maybe debatable,
> but using that now would allow users to avoid forcing the use of a more
> complex one, like anyhow, and can also be changed later.

The current output on error is: 

    Error: invalid input parameter

anyhow is already used in proxmox-router so I'd say we can just as well
use it. A simple bail! with the message you proposed should do the trick:

    Abort – unexpected choice "no"! Use enter for default or use 'y' or 'n'.




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

  reply	other threads:[~2024-04-25 10:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-18 11:49 [pbs-devel] [PATCH proxmox{, -backup} v5 0/2] close #4763: client: added command to forget backup group Gabriel Goller
2024-04-18 11:49 ` [pbs-devel] [PATCH proxmox v5 1/2] router: cli: added `ask_for_confirmation` helper Gabriel Goller
2024-04-24 19:03   ` Thomas Lamprecht
2024-04-25  8:52     ` Gabriel Goller
2024-04-25  9:42       ` Thomas Lamprecht
2024-04-25 10:37         ` Gabriel Goller [this message]
2024-04-25 11:32           ` Thomas Lamprecht
2024-04-18 11:49 ` [pbs-devel] [PATCH proxmox-backup v5 2/2] close #4763: client: add command to forget backup group Gabriel Goller
2024-04-26 12:37 ` [pbs-devel] [PATCH proxmox{, -backup} v5 0/2] close #4763: client: added " Gabriel Goller

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=D0T4Z7GOJWRH.1E15N94N7EKZL@proxmox.com \
    --to=g.goller@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    --cc=t.lamprecht@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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal