Re: [PATCH v5 7/7] scripts/ghes_inject: add a script to generate GHES error inject

From: Mauro Carvalho Chehab
Date: Fri Aug 09 2024 - 04:24:20 EST


Em Thu, 8 Aug 2024 19:33:32 -0400
John Snow <jsnow@xxxxxxxxxx> escreveu:

> > > Then here you'd use qmp.cmd (raises exception on QMPError) or qmp.cmd_raw
> > > or qmp.cmd_obj (returns the QMP response as the return value even if it
> > was
> > > an error.)
> >
> > Good to know, I'll try and see what fits best.
> >
>
> I might *suggest* you try to use the exception-raising interface and catch
> exceptions to interrogate expected errors as it aligns better with the
> "idiomatic python API" - I have no plans to support an external API that
> *returns* error objects except via the exception class. This approach will
> be easier to port when I drop the legacy interface in the future, see below.
>
> But, that said, whichever is easiest. We use all three interfaces in many
> places in the QEMU tree. I have no grounds to require you to use a specific
> one ;)

While a python-style exception handling is cool, I ended opting to use
cmd_obj(), as the script needs to catch the end of /machine/unattached/device[]
array, and using cmd_obj() made the conversion easier.

One of the things I missed at the documentation is a description of the
possible exceptions that cmd() could raise.

It is probably worth documenting it and placing them on a QMP-specific
error class, but a change like that would probably be incompatible with
the existing applications. Probably something to be considered on your
TODO list to move this from legacy ;-)

Anyway, I already folded the changes at the branch I'll be using as basis
for the next submission (be careful to use it, as I'm always rebasing it):

https://gitlab.com/mchehab_kernel/qemu/-/commit/62feb8f6037ab762a9848eb601a041fbbbe2a77a#b665bcbc1e5ae3a488f1c0f20f8c29ae640bfa63_0_17


Thanks,
Mauro