[libvirt] [PATCH 1/2] tools: use vshError rather than vshPrint on failure

Erik Skultety eskultet at redhat.com
Mon Nov 14 10:10:12 UTC 2016



----- Original Message -----
> From: "Michal Privoznik" <mprivozn at redhat.com>
> To: "Erik Skultety" <eskultet at redhat.com>, libvir-list at redhat.com
> Sent: Friday, November 11, 2016 4:24:16 PM
> Subject: Re: [libvirt] [PATCH 1/2] tools: use vshError rather than vshPrint on failure
> 
> On 11.11.2016 15:51, Erik Skultety wrote:
> > There were a few places in our virsh* code where instead of calling
> > vshError
> > on failure we called vshPrint.
> > 
> > Signed-off-by: Erik Skultety <eskultet at redhat.com>
> > ---
> >  tools/virsh-volume.c | 2 +-
> >  tools/vsh.c          | 4 ++--
> >  2 files changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c
> > index e8cef39..8831f44 100644
> > --- a/tools/virsh-volume.c
> > +++ b/tools/virsh-volume.c
> > @@ -605,7 +605,7 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd)
> >  
> >      newxml = virshMakeCloneXML(origxml, name);
> >      if (!newxml) {
> > -        vshPrint(ctl, "%s", _("Failed to allocate XML buffer"));
> > +        vshError(ctl, "%s", _("Failed to allocate XML buffer"));
> >          goto cleanup;
> >      }
> >  
> > diff --git a/tools/vsh.c b/tools/vsh.c
> > index 3ba09dd..f69c6dd 100644
> > --- a/tools/vsh.c
> > +++ b/tools/vsh.c
> > @@ -3269,7 +3269,7 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd)
> >          if (xml) {
> >              virBufferEscapeString(&xmlbuf, "%s", arg);
> >              if (virBufferError(&xmlbuf)) {
> > -                vshPrint(ctl, "%s", _("Failed to allocate XML buffer"));
> > +                vshError(ctl, "%s", _("Failed to allocate XML buffer"));
> >                  return false;
> >              }
> >              str = virBufferContentAndReset(&xmlbuf);
> > @@ -3286,7 +3286,7 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd)
> >      }
> >  
> >      if (virBufferError(&buf)) {
> > -        vshPrint(ctl, "%s", _("Failed to allocate XML buffer"));
> > +        vshError(ctl, "%s", _("Failed to allocate XML buffer"));
> >          return false;
> >      }
> >      arg = virBufferContentAndReset(&buf);
> > 
> 
> There are couple of other locations:
> cmdBlockCopy
> cmdUndefine
> 

Yes, I was a bit unsure about some of those you mention, but yeah, once it
says "{Copy, Commit, Pull} failed" or it does reset the libvirt error, it should
probably call vshError rather than vshPrint{whatever}...There isn't much of a
difference anyway, since vshError just writes to stderr and to a dedicated
logfile.

Erik

> But this is better too.
> 
> Michal
> 




More information about the libvir-list mailing list